Re: Odd memory issue -- not a newbie
Re: Odd memory issue -- not a newbie
- Subject: Re: Odd memory issue -- not a newbie
- From: Dietrich Epp <email@hidden>
- Date: Sun, 14 Dec 2003 16:18:16 -0800
On Dec 14, 2003, at 2:35 PM, Jonathan Jackel wrote:
On Dec 14, 2003, at 3:28 AM, Dietrich Epp wrote:
On Dec 13, 2003, at 4:57 PM, Jonathan Jackel wrote:
I'm printing a text view in a special way, so I use a custom view.
Mainly, I'm interested in the text view's text storage, because
that's
what I want to print. I tried to write my setter this way:
- (void)setMyStorage:(NSTextStorage *)newStorage
{
[newStorage retain];
[myStorage release];
myStorage = newStorage;
}
[snip]
Have you tried using:
- (void)setMyStorage:(NSTextStorage *)newStorage {
[myStorage release];
myStorage = [newStorage copy];
}
If the new storage object is immutable, then this is implemented as a
-retain and you don't get any more overhead. If it is mutable, then
you get a copy and you're okay if whatever is calling your function
modifies it, such as if it's an object wrapping an internal buffer
used for reading input.
In general, if you don't want a mutable object, always use -copy
instead of -retain, and if you make a new immutable class, make -copy
call -retain.
I know you are trying to help, and I thank you for trying, but you've
made a some errors (one of them serious) here that I don't want to let
go uncorrected. Sorry if this sounds a little bitchy, but ...
Geez, sorry. All I can say is that my guess is that you are getting a
subclass, and you don't want it, and when you create a new object you
don't have the subclass any more. Or there is an extra release
somewhere else. I didn't look up the documentation because it didn't
look terribly specific to whatever class you were using, and I usually
would do
foo* oldvalue = value
value = [newvalue retain]
[oldvalue release]
instead anyway, but I didn't want to clutter and my personal coding
style is to try and code the least amount that works even if it crashes
sometimes (not a place to discuss this).
Could you give more specifics? Have you tried debugging and printing
out what the values of your new object are, its class, etc?
_______________________________________________
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.