Re: question about classes, I think
Re: question about classes, I think
- Subject: Re: question about classes, I think
- From: "Alan Smith" <email@hidden>
- Date: Thu, 11 May 2006 23:28:54 -0400
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.
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 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.
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.
Don't take this the wrong way but... I think you really need to stop
go back and understand Cocoa memory management, object allocation and
initialization, difference between objects and pointers, etc. If you
don't have the basics down you just going to waste your own time.
No, I won't take it the wrong way. You're probably right, I should go
read that stuff.
Thanks, Alan
--
// Quotes from yours truly -------------------------
"You don't forget, you just don't remember."
"Maturity resides in the mind."
_______________________________________________
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