hi e.d.,
i assume you're using java (not NHibernate)? there is no conventional way to "remove an object from memory" in java -- the best you can do is null out your references to the object and wait for the garbage collector to take care of it when necessary and/or opportune to do so. if the object is fairly large, was recently created, and is completely unreferenced, it is likely to be collected quickly.
if you aren't using java, you can probably disregard the rest of this post :).
in any case, i don't think there is any way to accomplish this currently in Hibernate. it's a neat idea, though.
the problem is that hibernate isn't aware of where there might be other references to the object in memory. the best you could do is provide an alternate Session implementation that only maintains weak references to objects in Session (a weak reference means that the garbage collector is allowed to remove the referenced object from memory if necessary). this would be a *substantial* development effort.
an alternate architecture for controlling memory in hibernate involves using the object cache effectively. tune the cache to store frequently used objects at the VM level, and then keep your hibernate session lifespan relatively short (e.g. one per servlet requests) to keep objects only occasionally used out of residence. this is kind of a complementary strategy to yours -- "only save the objects that i want to keep" instead of "get rid of the objects i don't need"
jt
|