Re: substringWithRange: memory leak problem
Re: substringWithRange: memory leak problem
- Subject: Re: substringWithRange: memory leak problem
- From: John Clayton <email@hidden>
- Date: Tue, 27 Sep 2005 18:07:58 -0400
Hi, Joar.
First, thanks.
Second, I see what you mean. So, I could be leaking the string
created thusly, elsewhere, which is also what Jonathan was saying.
But, it seems I create four strings in this method with
stringByTrimmingCharactersInSet: and I can track them all down:
"myPid" is abandoned after I get the int value,
"myUcomm" is set as an instance field thusly,
- (void)setUcomm:(NSString *)newUcomm {
[newUcomm retain];
[ucomm release];
ucomm = newUcomm;
}
"started" is used to create a date and abandoned,
and finally, "command" is passed to another method to be parsed,
where so far as I can see it is never retained, released, or anything
else like that, though I do create a lot of substrings from it. But
never assign them back to the original pointer so I don't lose the
underlying object as far as I can tell. I abandon it after that.
This is a list of usages in this class:
TCSProcess.m: + (void) _parse:(NSString *)commandAndArgsString
intoProcess:(TCSProcess *)process {
TCSProcess.m: logTrace(@"_parse:%@ intoProcess:%
@",commandAndArgsString,process);
TCSProcess.m: NSScanner *scanner = [NSScanner
scannerWithString:commandAndArgsString];
TCSProcess.m: if([commandAndArgsString rangeOfString:[process
ucomm]].location != NSNotFound) {
TCSProcess.m: logError(@"Cannot find command in
commandAndArgsString");
TCSProcess.m: NSRange commRange = [commandAndArgsString
rangeOfString:commString];
TCSProcess.m: [commandAndArgsString substringFromIndex:
(commRange.location+commRange.length)];
So, could it be something like I lost the pointer to the object I set
"myUcomm" into and so it just sits around? But then, wouldn't I also
see that containing object leaking? As far as what MallocDebug is
saying, this is my last leak (for now ;-).
I wonder, at what point would I conclude this is a bug in
stringByTrimmingCharactersInSet: ? Or, what could I do to get more
info? Could I log retain/release in NSString? Well, thanks for all
your help.
Best,
John
2472 bytes in 121 nodes:
MDNXZoneMalloc
CFAllocatorAllocate
_CFRuntimeCreateInstance
__CFStringCreateImmutableFunnel3
CFStringCreateWithSubstring
-[NSCFString substringWithRange:]
-[NSString stringByTrimmingCharactersInSet:]
+[TCSProcess(Private) _processes:]
My understanding is that this is showing me objects which have
become unreachable, but please correct me if I'm wrong. I believe
it's an underlying call to substringWithRange: being performed in
stringByTrimmingCharactersInSet: that is the issue, and not my
explicit call.
Yes, that is what it will show you, but the backtrace is the
allocation event - not necessarily where it is leaked. I would look
at what you're doing with the strings passed to:
[process setUcomm:myUcomm];
[TCSProcess _parse:command intoProcess:process];
It is _highly_unlikely_ that there is a leak in a commonly used
Foundation methods such as this one - there are simply too many
users of that method for it to go unnoticed. I'm not saying that it
can't happen, just that it's much, much, more likely that it's in
your code...
j o a r
_______________________________________________
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