• 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: Segfault on NSKeyedUnarchiver release
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Segfault on NSKeyedUnarchiver release


  • Subject: Re: Segfault on NSKeyedUnarchiver release
  • From: Chris Kane <email@hidden>
  • Date: Sun, 31 Aug 2003 12:46:00 -0700

One of the objects returned by the unarchiver has been released out from under the unarchiver, so it is bad when it goes to release its own retain on it.

Turing on NSZombieEnabled (which you can do with NSZombieEnabled=YES; right before creating the unarchiver, say, for your debugging purposes) will probably cause a message about which class of object is being overreleased to appear in the console log. Often once you know the class of object, the problem becomes either to find.

Chris Kane
Cocoa Frameworks, Apple


On Aug 29, 2003, at 6:03 AM, Terje Tjervaag wrote:

Hi,

I'm having some problems retrieving my data model from a file that I've saved (document-based application). My application segfaults (EXC_BAD_ACCESS) after the NSKeyedUnarchiver I'm using is released. Here is the code loading the data:

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[self setTuneModel:[unarchiver decodeObjectForKey:@"tune"]];

NSLog(@"tune is: %i", [tune numberOfBars]);

[unarchiver finishDecoding];
[unarchiver release];

return YES;
}

I have included the message I used to try to debug this, because it seemed important. The message prints out the number of bars in a piece of music (tune) and actually prints the correct number as this code is run. This means that it is able to load the data correctly from the saved file. However, when my application goes to release the unarchiver it crashes, as you can see in the debugger output below:

#0 0x9068ba54 in objc_msgSend ()
#1 0x90131f64 in CFRelease ()
#2 0x9013dd40 in CFDictionaryRemoveAllValues ()
#3 0x9013db70 in CFBooleanGetValue ()
#4 0x90132084 in CFRelease ()
#5 0x97e4f110 in -[NSKeyedUnarchiver dealloc] ()
#6 0x00004b54 in -[MyDocument loadDataRepresentation:ofType:] (self=0x1a65c40, _cmd=0x906c069c, data=0x19b06b0, aType=0xd4fe0) at MyDocument.m:114/Users/terje/Documents/Programming/MyCoolApp/
#7 0x932816c0 in -[NSDocument loadFileWrapperRepresentation:ofType:] ()
#8 0x93281990 in -[NSDocument readFromFile:ofType:] ()
#9 0x931c5628 in -[NSDocument initWithContentsOfFile:ofType:] ()
#10 0x931c5248 in -[NSDocumentController makeDocumentWithContentsOfFile:ofType:] ()
#11 0x931c4a58 in -[NSDocumentController _openDocumentFileAt:display:] ()
#12 0x93283cd8 in -[NSDocumentController _openFile:] ()
#13 0x93207fb8 in -[NSApplication _doOpenFile:ok:tryTemp:] ()
#14 0x93207e50 in -[NSMenu removeItem:] ()
#15 0x931615d0 in +[NSDocumentController sharedDocumentController] ()
#16 0x91b56570 in aeProcessAppleEvent ()
#17 0x91b590cc in AEPutAttributePtr ()
#18 0x91b56478 in aeProcessAppleEvent ()
#19 0x96a83778 in AEProcessAppleEvent ()
#20 0x9308e0a8 in _DPSNextEvent ()
#21 0x930a0158 in -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] ()
#22 0x930b1d88 in -[NSApplication run] ()
#23 0x9315fc58 in NSApplicationMain ()
#24 0x000062f8 in main (argc=1, argv=0xbffffb70) at main.m:13/Users/terje/Documents/Programming/MyCoolApp/

The tune model consists of a base class, Tune, and 6 or 7 classes that are used by Tune. I thought this class structure might be the problem at first, but now I don't think so because I can alloc] init] and release as many instances as I want of this class and the app doesn't crash.

Have anyone experienced the same? Any tips regarding how I go about debugging this? I've been sitting here scratching my head for a few hours now, not really getting anywhere, so any help would be greatly appreciated!

Thanks!

Terje Tjervaag
_______________________________________________
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.

References: 
 >Segfault on NSKeyedUnarchiver release (From: Terje Tjervaag <email@hidden>)

  • Prev by Date: Re: How to programmatically create a Finder Alias?
  • Next by Date: Re: Drawing text "with NSText"
  • Previous by thread: Segfault on NSKeyedUnarchiver release
  • Next by thread: another simple C question please...
  • Index(es):
    • Date
    • Thread