Question

I have a data model with a skeleton (metadata) and large data objects. I'd like to keep the skeleton in memory and hold weak references to the data objects. I understand how I would implement this with plain Java, how I would create a WeakHashMap and clean up etc. But I'm wondering what would be the best way to resurrect the data objects after they have been GC'd?

Should I add a technical key to my map which I assign to a field in the data object, so I can find it again? Or should I call db.ext().getId() and use this ID as the technical key? If so, how would I get these keys when loading the parent? What do you suggest?

Was it helpful?

Solution

I would add a technical key to your large data-object. Then you store this technical key in your meta-data-class. Now on when you get the large data-object you get it by it's technical key. That quite a simple solution.

Db4o actually uses weak references to return the same object and avoid unnecessary deserialisation. So when you ask for a object and hasn’t been collected by the GC, db4o will return the same object.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top