cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Øyvind Harboe" <oyvind.har...@zylin.com>
Subject Re: Peak memory usage for Cayenne
Date Fri, 20 Jun 2008 08:31:24 GMT
On Fri, Jun 20, 2008 at 10:22 AM, Andrus Adamchik
<andrus@objectstyle.org> wrote:
>
>
>
> 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.

Ah! Thanks! I'll have to change the places in the code that
does this for *large* lists then.

>
>> 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.

a==b vs. q.getObjectId().equals(b.getObjectId()) was a bit of a
non-sequitor, I'll post
a seperate message.


>> 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.

I want to have a stab at creating a patch that has weak references for paged
queries... it has less impact on the application code.


-- 
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer

Mime
View raw message