Hi,
I'm developing a simple web application that store in a table an user
preference.
When a new user comes, i save a new record to a database using datacontext:
*
*
*datacontext.registerNewObject<http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#registerNewObject(java.lang.Object)>
*(Object<http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Object.html?is-external=true>
myobject);
*datacontext.**commitChanges<http://cayenne.apache.org/doc30/api/org/apache/cayenne/access/DataContext.html#commitChanges()>
*();
Cayenne perform an insert and all works fine.
I have 2 questions:
1) Reading the documentation the right way in a web application to create a
datacontext is per session:
http://cayenne.apache.org/doc30/obtaining-datacontext.html
What happens if i treat it as a singleton? ( So i have one instance for all
the users )
2) My web application has a high traffic, so i think that in a few time i've
"registered" in datacontext thousands of record. This objects are correctly
garbage collected or they stay in memory?
Reading the documentation:
Since Cayenne 3.0, by default DataContext uses weak references to store
registered objects. So objects are allowed to be garbage collected by the VM
if they are not referenced elsewhere in the application. "Elsewhere" usually
means one of the following:
- An object is directly or indirectly referenced by the application. [*NO
reference to them by any object in my application]*
- An object is a part of the cached query result stored by Cayenne. [*I
never configured cayenne for cache.. so if i'm not wrong, the default is
NO-CACHE]*
- An object is "dirty" (i.e. new, modified or deleted). In this case
Cayenne ensures that such object is retained at least until commit or
rollback. [*I perform always a commit after registering a new object]*
So... i think that the memory should be correctly freed.
N.B. I'm using Cayenne 3.0!
Thanks for help!
Davide
This archive was generated by hypermail 2.0.0 : Sat May 22 2010 - 09:03:46 UTC