Skip to Content
R Programming By Example
book

R Programming By Example

by Omar Trejo Navarro
December 2017
Beginner to intermediate
470 pages
12h 29m
English
Packt Publishing
Content preview from R Programming By Example

Finalizers

Sometimes, it's useful to run a function when the object is garbage collected. If you're not familiar with garbage collection, you can think of it as a way to liberate unused memory when an object is no longer referenced by other objects in the environment.

A useful case for this feature is when you want to make sure a file or database connection gets closed before an object is garbage collected. To do this, you can define a finalize() method, which will be called with no arguments when the object is garbage collected. To test this functionality, you can simply add a finalizer as follows to some of your objects and see when you get the "Finalizer called" message in the console:

A <- R6Class("A", public = list( finalize = function() ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Efficient R Programming

Efficient R Programming

Colin Gillespie, Robin Lovelace
R Programming

R Programming

Jared P. Lander

Publisher Resources

ISBN: 9781788292542Supplemental Content