Reclaiming some memory back

4 views
Skip to first unread message

yohann

unread,
May 12, 2009, 4:08:23 AM5/12/09
to sqlitepersistentobjects-user, fil...@mac.com
Hi everybody

So far I'm very happy with SqlitePo?.

I have a question concerning my code practices.

In my app I do loop checks and updates on my my SqlitePo? Object after
a request to sync clent DB with a server. I mean almost all rows and
tables go through a save method and newly created rows are often also
initialized after this request

When I perform such operations, If I check ObjectAlloc? in Instrument.
I Track down NSKeyValueObservance which have been allocated but not
freed. they appear in red at 100% meaning that they were allocated but
never released.They also consume I suppose GeneralBlocks? alongs whith
those NSObject.

The stack trace links down to line 1319 in SQLitePersistenObject.m for
rev 135 in the init metod.

I guess it's something normal, but I would think that using
[SQLitePersistentObject clearCache] would remove all observers as
well.

In my app, I need this memory back but I'm not sure how I would best
do that. Anybody could give me a hint on how to reclaim this memory
back. Can I discard thos observers and how ?

In general, has anybody developped for themselves good memory
management practices when using SqlitePo in an app ?

Thank you very much if someone can help

Best to all of you

Yohann

Andrew W. Donoho

unread,
May 12, 2009, 9:42:50 AM5/12/09
to sqlitepersiste...@googlegroups.com

On May 12, 2009, at 3:08 AM, yohann wrote:

> When I perform such operations, If I check ObjectAlloc? in Instrument.
> I Track down NSKeyValueObservance which have been allocated but not
> freed. they appear in red at 100% meaning that they were allocated but
> never released.They also consume I suppose GeneralBlocks? alongs whith
> those NSObject.
>
> The stack trace links down to line 1319 in SQLitePersistenObject.m for
> rev 135 in the init metod.
>
> I guess it's something normal, but I would think that using
> [SQLitePersistentObject clearCache] would remove all observers as
> well.

Hi Yohann,

The observer is only used on itself. SQLPO starts the observing in
its -init and then, IMO, should stop observing it in its -dealloc.
Currently, there are no calls to -removeObserver:forKeyPath: in SQLPO.

I would say you've found a memory leak. Yay!


Here is my patch for -dealloc:

- (void) dealloc
{
[[self class] unregisterObject:self]; // Remove this instance from
the cache.

// Stop observing ourselves.
for (NSString *oneProp in [[self class] propertiesWithEncodedTypes])
[self removeObserver:self forKeyPath:oneProp];

[super dealloc];
} // dealloc

> In general, has anybody developped for themselves good memory
> management practices when using SqlitePo in an app ?

If the above fixes your problem, then what are you looking for?

We should all remember that the lead architect of this project, Jeff
LaMarche, has chosen to focus his future efforts on exploiting Core
Data on the iPhone. I, myself, will be making that transition to Core
Data shortly after the release of the 3.0 code. IOW, I would not
expend too much effort trying to tightly embrace SQLPO in your project.

Anon,
Andrew

yohann

unread,
May 14, 2009, 4:50:10 AM5/14/09
to sqlitepersistentobjects-user
Hi Andrew !

Many thanks for your answer,I didn't receive the email alert for it
though ;-)

I corrected it just the way you said shortly after my post but wanted
confirmation from an experienced developper before posting.

Hey Guys, it's my first ever patch in an external library, congrat to
me and champagne for everybody of course !

SqlitePo is otherwise a very consistent and straightforward library. I
plan on my side to suport iphone OS2 at least 6 other months.So untill
that time I will keep an eye on pre V3.0 OS tools.

Best

Yohann



Reply all
Reply to author
Forward
0 new messages