I've been having problems with my app crashing with an EXC_BAD_ACCESS while 
unarchiving a saved data file. The file is a graph representation of musical 
structure, created by a machine learning algorithm. When the file/graph is 
small there are no problems, but as I add more training material, and the file 
increases in size, at a certain point it starts crashing during unarchiving. 
Strangely, it has no problems saving the file, only unarchiving. The file is 
saved using:

[NSKeyedArchiver archiveRootObject:model toFile:filePath];

Pretty straightforward. NSZombieEnabled gives no info, and code analysis 
reveals no memory warnings. I've been over the code many, many times, and 
haven't been able to track down a reasonable cause. The graph does have 
circular references/loops in some cases (i.e., node B points to a "parent" node 
A, which holds a reference to node B as a "child"), but I doubt that's the 
problem, since smaller files would have the same basic structure -- I used the 
archiveRootObject, which is supposed to deal with this situation (in my 
understanding). 

The last 30 frames of the backtrace:

* thread #1: tid = 0x2603, 0x959f115c CoreFoundation`__CFStringEncodeByteStream 
+ 12, stop reason = EXC_BAD_ACCESS (code=2, address=0xbf81acfc)
    frame #0: 0x959f115c CoreFoundation`__CFStringEncodeByteStream + 12
    frame #1: 0x95a27a0a CoreFoundation`CFStringGetCString + 922
    frame #2: 0x95a683d7 CoreFoundation`-[__NSCFString 
getCString:maxLength:encoding:] + 119
    frame #3: 0x9b693190 Foundation`NSClassFromString + 82
    frame #4: 0x9b6cb4bf Foundation`_decodeObjectBinary + 2191
    frame #5: 0x9b6ccec9 Foundation`-[NSKeyedUnarchiver 
_decodeArrayOfObjectsForKey:] + 1533
    frame #6: 0x9b6a06e7 Foundation`-[NSArray(NSArray) initWithCoder:] + 693
    frame #7: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #8: 0x9b6caa66 Foundation`_decodeObject + 197
    frame #9: 0x0014c017 ManuScore`-[CbCMNode initWithCoder:] + 663 at 
CbCMNode.m:1176
    frame #10: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #11: 0x9b6ccec9 Foundation`-[NSKeyedUnarchiver 
_decodeArrayOfObjectsForKey:] + 1533
    frame #12: 0x9b6a06e7 Foundation`-[NSArray(NSArray) initWithCoder:] + 693
    frame #13: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #14: 0x9b6caa66 Foundation`_decodeObject + 197
    frame #15: 0x0014c017 ManuScore`-[CbCMNode initWithCoder:] + 663 at 
CbCMNode.m:1176
    frame #16: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #17: 0x9b6ccec9 Foundation`-[NSKeyedUnarchiver 
_decodeArrayOfObjectsForKey:] + 1533
    frame #18: 0x9b6a06e7 Foundation`-[NSArray(NSArray) initWithCoder:] + 693
    frame #19: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #20: 0x9b6caa66 Foundation`_decodeObject + 197
    frame #21: 0x0014c017 ManuScore`-[CbCMNode initWithCoder:] + 663 at 
CbCMNode.m:1176
    frame #22: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #23: 0x9b6ccec9 Foundation`-[NSKeyedUnarchiver 
_decodeArrayOfObjectsForKey:] + 1533
    frame #24: 0x9b6a06e7 Foundation`-[NSArray(NSArray) initWithCoder:] + 693
    frame #25: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #26: 0x9b6caa66 Foundation`_decodeObject + 197
    frame #27: 0x0014c017 ManuScore`-[CbCMNode initWithCoder:] + 663 at 
CbCMNode.m:1176
    frame #28: 0x9b6cb9c0 Foundation`_decodeObjectBinary + 3472
    frame #29: 0x9b6ccec9 Foundation`-[NSKeyedUnarchiver 
_decodeArrayOfObjectsForKey:] + 1533
    frame #30: 0x9b6a06e7 Foundation`-[NSArray(NSArray) initWithCoder:] + 693

This morning, I tried enabling Guard Malloc (on its own, without zombies), and 
was surprised to see the app crash during training, with the following error:

GuardMalloc[ManuScore-2438]: Failed to VM allocate 1864016 bytes
GuardMalloc[ManuScore-2438]: Explicitly trapping into debugger!!!


Is it simply running out of VM while trying to build the graph? If so, why 
doesn't this happen with Guard Malloc off? Also, with zombies and guard malloc 
off, why is it only when reading the file that the app crashes, not during 
training (i.e., while the graph is being built)? 

One thing I have noticed, that seems pretty weird, is that the complete 
backtrace when it crashes during unarchiving is 25962 frames long! Could it 
simply be that it's running out of memory while trying to unarchive (i.e., on 
the stack)? If so, how can I get around that? Some sort of caching, perhaps?
The file is only 9.6 MB, so it's not a massive file... 

Any thoughts appreciated.

J.


------------------------------------------------------
James B. Maxwell
Composer/Researcher/PhD Candidate







_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to