Re: question about classes, I think
Re: question about classes, I think
- Subject: Re: question about classes, I think
- From: "Shawn Erickson" <email@hidden>
- Date: Fri, 12 May 2006 13:42:27 -0700
On 5/11/06, Alan Smith <email@hidden> wrote:
> Why do you retain what you alloc here? When you alloc something it has
> an implicit retain that you have to balance later on with a
> release/autorelease (likely in your classes dealloc method). Likely
> you are over retaining tableContents which will likely leads to a
> leak.
I did that because I wasn't sure if the object was getting released
too soon, automatically.
Make sure to understand the memory management paradigm used by the
Cocoa framework.
> This is a weird bit'o code. What is pluginHelper? It looks like it is
> a class name since you send it an alloc message. If so it really
> should start with an upper case letter and some prefix (see [1]). The
> weird things is after sending it an alloc message you then proceed to
> send it a pluginsInFolder:forGame message which is a rather strangely
> named init method IMHO (if that is truly what it is). Maybe you want
> pluginsInFolder:forGame: to be a class method? Also if the alloc
> pluginHelper supports is really the normal -[NSObject alloc] you are
> leaking an instance of pluginHelper (unless pluginsInFolder:forGame:
> releases it... which would be a bad coding style to follow).
pluginHelper is a class. pluginsInFolder:forGame: is a method of
pluginHelper that returns a NSMutableArray. I send pluginHelper the
alloc bit because it would say "pluginHelper may not respond to
'pluginsInFolder:forGame:'." Adding the alloc made it work.
So it sounds like you want it to be a class method [1]...
@interface PluginHelper
+ (NSMutableArray*) pluginsInFolder:(blah)blah forGame:(blah)blah;
@end
@interface PluginHelper
+ (NSMutableArray*) pluginsInFolder:(blah)blah forGame:(blah)blah
{
...blah...
}
...
array = [PluginHelper pluginsInFolder:blah forGame:blah];
> So you retain contents. Set tableContents to point at what contents
> points at which losses what tableContents used to point at (the
> instance you allocated in awakeFromNib). Then you release contents
> (which is the same thing that tableContents points at). I see no
> reason for the retain or release here and you likely don't want to do
> the tableContents assignment as you are (since you are leaking what
> tableContents used to point at).
Well, it used to be that tableContents was put in place of contents.
It received the array right away from the pluginHelper method. It
hasn't made a difference one way or the other.
You are losing a reference to an object by doing that assignment and
hence losing the ability to release the object that you allocated.
> Again this weird alloc of pluginHelper then sending a message other
> then what one would expect to be an initializer. Again maybe you want
> managePlugins:inGamesFolder: to be a class method?
I need that to be a method of pluginHelper so I can access it from
other table dataSources.
See above.
-Shawn
[1]
_______________________________________________
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