On Jun 20, 2008, at 10:45 AM, Øyvind Harboe wrote:
> 1. Consider the code below. Will all the objects from the query
> be locked in memory?
>
> query=new SelectQuery(Foo.class);
> query.setPageSize(1000); /* does this matter? */
> /* Does performQuery return a clever implementation of
> a List that does not lock the CayenneDataObjects into memory?
> */
> l=context.performQuery(query);
> while (i.hasNext())
> {
> Foo f=(Foo) i.next();
>
> .... do some processing here that ...
>
>
> }
>
> 2. When does peak memory usage occur above?
At the end of the the iterator when all pages are resolved.
> 3. Can a CayenneDataObject be garbage collected as long as it's
> DataContext is in scope?
>
> I'm wondering because as far as I have understood the two if
> statements below are equivalent when a & b are CayenneDataObjects
> in the same DataContext.
It is stored using a weak reference, so yes, it can be garbage
collected if there are no other references to the object in the code.
> That is if 'a' can be garbage collected during the lifetime of the
> DataContext, then 'a' is points to different objects during the
> lifetime of CayenneDataObject's and a==b just 'barely' works.
Not "barely". It always works. If you have var "a" pointing to a given
object, that fact alone will prevent garbage collection within the
scope of "a" definition.
> 4. Should I consider some "clever" implementation of a query that
> ensures that only a small amount of CayenneDataObject's are
> locked in memory at the time?
>
> Some ideas:
>
> - use performIteratedQuery() w/setPageSize()
> - ResultIterator.nextDataRow() is a bit strange: it returns a Map<>,
> but
> perhaps I can safely upcast that.
> - use objectFromdataRow()
Yes, use 'performIteratedQuery' - it was designed for serial
processing of arbitrary size lists.
Andrus
This archive was generated by hypermail 2.0.0 : Fri Jun 20 2008 - 04:22:39 EDT