[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Memory Management
From: |
David Chisnall |
Subject: |
Re: Memory Management |
Date: |
Tue, 14 Jul 2009 23:53:17 +0100 |
On 14 Jul 2009, at 23:44, Stefan Bidigaray wrote:
According to the apple docs whenever a sound is created using -
iniWithContentsOfFile:byReference: or a name is set using -setName:
I must be able to later find it using the +soundNamed: method, at
least that's how I understand it. Because the NSSound object is
retained when added to the nameDict dictionary I will have 1 extra
retain that what I would want and the sound will never get
deallocated. The problem I'm having a hard time solving here is: I
must keep the NSSound object in nameDict in order to be able to
return it whenever +soundNamed: is called, but doing so will
increase my ref count +1 and I do not want that.
Named sounds should not be released - they are expected to last the
entire duration of the program. In -setName: you should have
something like this:
[self retain];
// Remove from the dictionary if it previously had a name
if (_name)
{
[nameDict removeObjectForKey: _name];
}
// Add to the dictionary if the name is non-nil
if (aName)
{
[nameDict setObject: self forKey: aName];
}
ASSIGN(_name, aName);
[self release];
David
P.S. If you want a proper code review, you can upload a diff to the
Étoilé review board (http://review.etoileos.com) - it is set up for
reviewing GNUstep code as well as Étoilé, just select the correct
repository root.