[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory Management
From: |
Adam Fedor |
Subject: |
Re: Memory Management |
Date: |
Tue, 14 Jul 2009 13:42:09 -0600 |
On Jul 13, 2009, at 9:01 PM, Stefan Bidigaray wrote:
I'm debugging the NSSound stuff and have run into a bit of a problem
with memory management and the whole RETAIN/RELEASE stuff... I'm
sure my probably has do to with being a novice.
Anyway, in the -dealloc method of NSSound I call RELEASE(_data) and
right after it [nameDict removeObjectForKey: _name]. The dictionary
nameDict contains as a key the sound name and as a value the NSSound
object associated with it. Well, whenever this method is called it
will go ahead and call NSSound's -dealloc again which in turn sends
another call out to RELEASE(_data). As you can imagine it blows up
at this point.
So my question is: Would adding a RETAIN(self) just before the call
to [nameDict removeObjectForKey: _name] solve this issue? Anything
else? This seems to do the trick, but I'm wondering if it's correct.
There must be something wrong somewhere else. If dealloc is being
called more than once, then somewhere there are two many 'releases'
for the number of 'retains' you have.
In fact, if the NSSound is stored in nameDict, then dealloc should
have never been called in the first place, as nameDict implicitly
retains the NSSound (if that is the only place that the NSSound is
removed from nameDict). So that means you have at least two too many
releases somewhere else.