[R] hash::hash(...) assignment & clearing

Murat Tasan mmuurr at gmail.com
Wed Jun 17 04:04:41 CEST 2015


The hash package implements hashmaps which must be cleared prior to
removal to free memory, e.g.:

> x <- hash(some_long_list_of_keys_and_values_here)
> clear(x)
> rm(x)

I first assumed this held for re-assignment, too... e.g. one should:

> x <- hash(some_long_list_of_keys_and_values_here)
> clear(x)
> x <- hash(some_other_long_list_of_keys_and_values_here)

With the clear(x) between the re-assignment of x to prevent memory leaks.

After some testing, though, I'm now not so sure.
I basically repeated this cycle:

> x <- hash(randomly_generated_long_list_of_keys_and_values_here)
> gc()

Memory usage grew only in the first few (3) cycles of this, but then
remained stable as x continued to be re-assigned.
Does anyone know if the assignment operator for a hash object has been
written to force a clear() operation?

Cheers,

-m



More information about the R-help mailing list