• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: (NSThread) crash after pool release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (NSThread) crash after pool release


  • Subject: Re: (NSThread) crash after pool release
  • From: Brent Gulanowski <email@hidden>
  • Date: Sun, 25 Aug 2002 10:08:27 -0400

In case no one got back to you on this, the problem is that you were assigning temp to an empty NSString, and then re-assigning it to the results of a sub-string message a bit further down. So you are leaking the first empty string, then you are trying to release it, but in fact you are releasing the already auto-released sub-string.

Remember the "temp" variable is only a pointer.

Brent

On Thursday, August 22, 2002, at 07:15 AM, email@hidden wrote:

Well I made a workaround by removing the NSString temp. But I do want to know why temp creates a problem...
Am I releasing it in a wrong order?

Erick
On donderdag, aug 22, 2002, at 13:06 Europe/Amsterdam, email@hidden wrote:

I have a little problem here that I haven't run into before.
After finishing all the code in a thread I've created I release all the
objects I alloc and the NSAutoreleasePool as last the one.

When I do this I get a EXC_BAD_ACCESS and has exited due to signal 11
(SIGSEGV) error.
It runs until I release the pool (according to the docs I have to do
this manually, right?)
So why should it crash, am i overlooking something???

Thanks,

Erick

- (void)copyData:(NSFileHandle*)handle {
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];
NSRange whereTime,whereMS,copyRange;
NSString *temp;
NSString *string=[[NSString alloc] initWithData:[handle
readDataToEndOfFile] encoding:NSASCIIStringEncoding];

The line here is, I think, effectively meaningless.

temp = [[NSString alloc] init];
whereTime = [string rangeOfString:@"time="
options:NSCaseInsensitiveSearch];
NSLog(@"%d",whereTime);
whereMS = [string rangeOfString:@" ms"
options:NSCaseInsensitiveSearch];
NSLog(@"%d",whereMS);

copyRange = NSMakeRange(whereTime.location +
whereTime.length+1,whereMS.location- 1 - (whereTime.location +
whereTime.length));

Your initial "temp" is now leaked here.

temp = [string substringWithRange: copyRange];

[timeText setString:temp];


You are trying to release your leaked string here, but instead you release the string that came back from "substringWithRange:" above. It was already autoreleased, hence crashola.
[temp release];
[string release];
[pool release];
}
_______________________________________________
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.


--
Inkubator: creating free, open source Mac games.
http://inkubator.idevgames.com - homepage
http://www.sourceforge.net/project/inkubator - project page
http://64.246.17.165/forum/forumdisplay.php?s=&forumid=17 - discussion forums
_______________________________________________
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.
References: 
 >Re: (NSThread) crash after pool release (From: email@hidden)

  • Prev by Date: Re: Getting the IP address with remote DO
  • Next by Date: Cocoa unzip?
  • Previous by thread: Re: (NSThread) crash after pool release
  • Next by thread: Bundle loading
  • Index(es):
    • Date
    • Thread