Re: [for memory geek] NSNotificationCenter possible memory leak?
Re: [for memory geek] NSNotificationCenter possible memory leak?
- Subject: Re: [for memory geek] NSNotificationCenter possible memory leak?
- From: Giovanni Donelli <email@hidden>
- Date: Thu, 14 Jul 2005 00:20:11 -0700
I see what you are saying however the memory seems not to be released
by the NSNotificationCenter
even after few seconds.
To check the memory leak I'm using an application developed
internally in my company (which we have been using reliably for a
while), but with the command top it is noticeable the increment of
memory allocated too.
any other idea on how to purge NSNotificationCenter?
I really don't see the reason why there should be cached copies of
notification when I explicitly asked to have them removed.
thanks for your reply!
Giovanni
Donelleschi
On 13 Jul 2005, at 7:15 PM, Fritz Anderson wrote:
What leads you to believe that this is actually a leak, and not
just a retention of 4096 bytes for every new notification type you
create? Do you have a report from a leak-detecting utility that
says memory remained allocated after it was no longer referenced,
or are you just noticing that your curious function consumes memory?
I'd find it plausible that when it learns of a new kind of
notification (you create 20 new notifications),
NSNotificationCenter allocates facilities for that notification,
and caches those facilities even when the last observer for that
notification is removed.
It is not reasonable to assume that a notification type
"disappears," never to be heard from again, when nobody is
registered for it. NSNotificationCenter is probably not designed
around that assumption. Your code, which makes add/removeObserver
look like a reference tally like retain/release, is misleading on
this point.
-- F
On 13 Jul 2005, at 4:13 PM, Giovanni Donelli wrote:
Hi,
I can't figure out how I can get rid of the following memory
leak which is about 80KB, on my PowerBook G4.
There is something connected with the fact that 'name' is randomly
generated... however I tried for few hours to understand what was
wrong.. and here I am now to you :-)
here is the function that leads to the memory leak of about 80KB
void memoryLeak()
{
int i;
NSNotificationCenter* nc = [NSNotificationCenter
defaultCenter];
for (i=0 ; i < 20; i++)
{
NSObject *obj = [NSObject new];
NSString* name = [[NSString alloc]
initWithFormat:@"%d", random()];
[nc addObserver:obj
selector:@selector(doenstMatter:)
name:name
object:nil];
[nc removeObserver:obj
name:name
object:nil];
[name release];
[obj release];
}
}
Thank you!
Giovanni Donelli
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40manoverboard.org
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden