You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Marc Gabriel-Willem <ma...@side-international.com> on 2007/04/10 09:18:06 UTC
DataContext cleanup
Hi,
In some situation, I'm creating a child data context.
Is there a good way to clean-up that child data context properly (in
order to facilitate the JVM GC process) when I finished with it ?
Thank you.
Marc
Re: DataContext cleanup
Posted by Andrey Razumovsky <ra...@gmail.com>.
It should. No objects registered with the context are returned from your
function, and context itself is registered in event mechanizms using weak
references
2009/3/10 Borut Bolčina <bo...@gmail.com>
> Hi, just a sanity check:
>
> I have a this method in my PersistenceManager class:
>
> public Principal findPrincipalByUsername(String username) {
> DataContext context = DataContext.createDataContext();
> Expression e =
> ExpressionFactory.matchExp(User.USERNAME_PROPERTY, username);
> SelectQuery query = new SelectQuery(User.class, e);
> List users = context.performQuery(query);
>
> User user = null;
> Principal principal = null;
> if (users.size() > 0) {
> user = (User) users.get(0);
> principal = new Principal();
> principal.setUsername(user.getUsername());
> Profile profile = user.getProfiles().get(0);
> principal.setFirstName(profile.getFirstName());
> principal.setLastName(profile.getLastName());
> }
>
> return principal;
> }
>
> Is DataContext (context) garbage collected?
>
> -Borut
>
>
> 2007/4/10 Andrus Adamchik <an...@objectstyle.org>:
> > The context is garbage collected once the context itself and all its
> objects
> > go out of scope. So make sure you don't retain references to the objects
> > registered in the context and you should be fine.
> >
> > Andrus
> >
> >
> > On Apr 10, 2007, at 11:18 AM, Marc Gabriel-Willem wrote:
> >>
> >> Hi,
> >>
> >>
> >>
> >> In some situation, I'm creating a child data context.
> >>
> >> Is there a good way to clean-up that child data context properly (in
> >> order to facilitate the JVM GC process) when I finished with it ?
> >>
> >>
> >>
> >> Thank you.
> >>
> >> Marc
> >>
> >
> >
>
Re: DataContext cleanup
Posted by Borut Bolčina <bo...@gmail.com>.
Hi, just a sanity check:
I have a this method in my PersistenceManager class:
public Principal findPrincipalByUsername(String username) {
DataContext context = DataContext.createDataContext();
Expression e =
ExpressionFactory.matchExp(User.USERNAME_PROPERTY, username);
SelectQuery query = new SelectQuery(User.class, e);
List users = context.performQuery(query);
User user = null;
Principal principal = null;
if (users.size() > 0) {
user = (User) users.get(0);
principal = new Principal();
principal.setUsername(user.getUsername());
Profile profile = user.getProfiles().get(0);
principal.setFirstName(profile.getFirstName());
principal.setLastName(profile.getLastName());
}
return principal;
}
Is DataContext (context) garbage collected?
-Borut
2007/4/10 Andrus Adamchik <an...@objectstyle.org>:
> The context is garbage collected once the context itself and all its objects
> go out of scope. So make sure you don't retain references to the objects
> registered in the context and you should be fine.
>
> Andrus
>
>
> On Apr 10, 2007, at 11:18 AM, Marc Gabriel-Willem wrote:
>>
>> Hi,
>>
>>
>>
>> In some situation, I'm creating a child data context.
>>
>> Is there a good way to clean-up that child data context properly (in
>> order to facilitate the JVM GC process) when I finished with it ?
>>
>>
>>
>> Thank you.
>>
>> Marc
>>
>
>
Re: DataContext cleanup
Posted by Andrus Adamchik <an...@objectstyle.org>.
The context is garbage collected once the context itself and all its
objects go out of scope. So make sure you don't retain references to
the objects registered in the context and you should be fine.
Andrus
On Apr 10, 2007, at 11:18 AM, Marc Gabriel-Willem wrote:
> Hi,
>
>
>
> In some situation, I'm creating a child data context.
>
> Is there a good way to clean-up that child data context properly (in
> order to facilitate the JVM GC process) when I finished with it ?
>
>
>
> Thank you.
>
> Marc
>