tags:

views:

13

answers:

1

I'm trying to understand when I should call Query.close(Object) or Query.closeAll();

From the docs I see that it will "close a query result" and "release all resources associated with it," but what does "close" mean? Does it mean I can't use objects that I get out of a Query after I've called close on them?

I ask because I'm trying to compartmentalize my code with functions like getUser(id), which will create a Query, fetch the User, and destroy the query. If I have to keep the Query around just to access the User, then I can't really do that compartmentalization.

What happens if I don't call close on an object? Will it get collected as garbage? Will I be able to access that object later?

Please let me know if I can further specify my question somehow.

+1  A: 

You can't use the query results since you closed them (i.e the List object you got back from query.execute). You can access the objects in the results ... if you copied them to your own List, or made references to them in your code. Failure to call close can leak memory

DataNucleus