Setting the context to null is unlikely to help... it is probably
bound to the thread.
You will at least need:
DataContext.bindThreadDataContext(null);
dataContext = null;
If you have any objects that are holding onto other references to the
DataContext or *any other Cayenne-controlled objects in the context*,
you must null them as well. A single reference will prevent the
DataContext from getting collected. To help this process along, I
often do a dataContext.rollbackChanges() before discarding, though I'm
not convinced its in any way helpful. It certainly makes me feel
better though. :)
> context.getObjectStore().getDataRowCache().clear();
> context.unregisterObjects(context.newObjects());
> context.unregisterObjects(context.deletedObjects());
> context.unregisterObjects(context.modifiedObjects());
> System.gc();
>
As far as this goes... the first and most important point is that you
should not call System.gc(). This is really intended for debugging /
test environments. Each JVM can choose whether or not to even
implement this call, and the ones that do do not guarantee a gc will
happen every time you call it.. particularly at peak performance
times. Therefore any problem that is solved by adding this call is not
actually solved at all.
context.unregisterObjects(context.getObjectStore().getObjects()) is
actually what you want.
This *will* reduce memory consumption if the object references are
removed, but as mentioned by others, its probably better to discard
the context anyway to get rid of datarow and querymap caching.
Cris
This archive was generated by hypermail 2.0.0 : Fri Dec 23 2005 - 09:16:45 EST