Re: Some confusion on memory management
Re: Some confusion on memory management
- Subject: Re: Some confusion on memory management
- From: Stephane <email@hidden>
- Date: Fri, 20 Jan 2006 16:20:52 +0100
El Jan 20, 2006, a las 4:09 PM, Mike Abdullah escribió:
I am still getting to grips with Cocoa, and would like to ask a
question on memory management that will hopefully clear things up
for me.
I have my subclass of NSDocument, and my document window contains a
single text view.
The idea, is that every time, the text in the text view is changed
by the user, my NSDocument will change its internal value
accordingly. I have the delegate system for the text view set up
fine, so that when the text does change, I carry out the command:
[self setMyString: newString];
So, in my class there are 2 methods: setMyString and myString. The
thing I don't fully understand is how to properly get the internal
value of myString to be remembered throughout the life of the
NSDocument. In my header file I have placed:
NSString *myString;
And in the two methods I have this:
- (void)setMyString:(NSString *)newString
{
myString = newString;
}
-(NSString *)myString
{
return myString;
}
However, I am sure this is not entirely correct, since it seems
that after a while, the NSDocument "forgets" the value of myString,
so I am sure that I have the memory management wrong! Also, should
I really be using NSString? Would I be better off with
NSMutableString?
If you are using the string method of NSTextView, it probably would
be better to copy the string as this is somehow returning an internal
value of the NSTextView which is going to change as you change the
text in it or remove it from the view hierarchy.
My $0.02 before tax.
_______________________________________________
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