[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

IdentityMap, Memory leaks, and reference counting

List Recv

4/27/2006 8:23:00 PM

A simple IdentityMap (for O/R mappers, like ActiveRecord) can be coded
in a few lines of Ruby - but, it will cause memory leaks, as a a
reference will be kept even when no one else has one.

Is there anyway to tell Ruby not to count a particular reference
towards garbage collection.

EG:
def store(product)
map[Product][1422] = NoRefCount(product)
end

2 Answers

Sam Smoot

4/27/2006 10:11:00 PM

0

WeakRef will do what your asking it looks like:
http://www.ruby-doc.org/stdlib/libdoc/weakref/rdoc/...

Also, some O/R Mappers like NHibernate use IdentityMaps scoped to the
UnitOfWork so that the IdentityMap goes out of scope when the
UnitOfWork (Session) does.

List Recv

4/28/2006 2:14:00 AM

0

Sam,

Thanks for the, er, reference.

I thought about scoping to a UnitOfWork. But my intended application
is to drop in to ActiveRecord (after spending too long puzzling over a
bug that IdentityMap's are supposed to solve), and introducing a UOW
would change the entire way AR is used.