Re: retain variables between classes
Re: retain variables between classes
- Subject: Re: retain variables between classes
- From: "Louis C. Sacha" <email@hidden>
- Date: Tue, 16 Dec 2003 22:09:37 -0800
Hello...
<mini-rant>
People: please read the question thoroughly before assuming that you
need to lecture someone on what you believe to be the proper
retain/release behavior. I realize everyone is trying to be helpful,
but...
It seems like a large number of the questions posted to the list
seem to turn into "how should you retain/release objects in setter
methods". Yes, I know it is a common problem, and I agree that it is
good to point out some of the available documentation about doing it
correctly, but posting a link should be sufficient. I know there is a
bit of a delay between the time a response to a message is sent to
the list and it shows up, so it's difficult to know if someone has
already pointed it out , but it usually turns into a chain reaction
that causes the original question to be mostly ignored. Maybe we
should just automagically post a message once a week that lists all
the acceptable ways to to retain/release in setter methods so that no
one feels the need to jump in and post their retain/release code,
which half of the time turns out to be wrong/problematic...
</mini-rant>
The problem referred to in his post has nothing to do with
retain/release issues, regardless of the issue with his
retain/release code. Read Carefully:
However when later
methods and delegates are called of AClass the array it the old one that was
defined in the initial init call.
This is NOT a symptom of retain/release problems.
There are several reasons why this might occur. The most likely one
is that you are instantiating your aClass in a nib and also in your
mainClass, and when you call the setInfo: method you are talking to
one of them and the other that you are accessing still has the old
value. Second, you may have mis-typed the name of an instance
variable (which would be generating a compiler error or warning) , or
have two similar variables and you are accessing the wrong one in
either your setter or access methods.
Hope that helps...
Louis
I have two classes MainClass and AClass
AClass has a method (with data item array)
-(void)setInfo: (NSMutableArray *)inArray
{
[array release];
[inArray retain];
array = inArray; // also tried array = [inArray mutableCopy]
}
MainClass has an AClass defined and calls this method passing in a mutable
array and when i debug everything is copied fine. However when later
methods and delegates are called of AClass the array it the old one that was
defined in the initial init call. I checked init and it is only
being called once so
I am assuming that in the setInfo function I am only copying it for
the duration
of the method .... how can I get it to last more than the duration
of the setInfo
method?
any ideas are greatly appreciated
-j
________________________________________________________________
Sent via the WebMail system at 1st.net
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.