Master data crash with EXC_BAD_ACCESS on one of my objects

Hope someone can help me debug this issue as EXC_BAD_ACCESS is the only error I get. I also tried to enable NSZombieEnabled, but can't get any more information as far as I can tell.

This problem. I have four objects:

A β†’ B β†’ C β†’ D

Where the arrow symbolizes the set: β€œA” contains the β€œmany-to-many” relation to β€œB”, β€œB” - the β€œmany-to-many” relation to β€œC”, etc. To create an object, I use:

id dto = [NSEntityDescription insertNewObjectForEntityForName:@"A" inManagedObjectContext:context]; NSLog(@"DTO: %@", dto); 

and this seems to work for A, B, and C. However, when used on object D, the application crashes with EXC_BAD_ACCESS. It seems that the problem occurs when accessing the object, since the program succeeds when commenting on NSLog and other methods that access the dto object.

Update:

Console output

 GNU gdb 6.3.50-20050815 (Apple version gdb-1346) (Fri Sep 18 20:40:51 UTC 2009) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "x86_64-apple-darwin".sharedlibrary apply-load-rules all Attaching to process 3100. Program received signal: "EXC_BAD_ACCESS". warning: Unable to restore previously selected frame. No memory available to program now: unsafe to call malloc warning: check_safe_call: could not restore current frame Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.) warning: Unable to restore previously selected frame. 

stack
The stack trace is very large (?). When debugging, it loads "62826 stack frames." Showing part of this: alt text alt text
Lines # 8- # 41 are repeated for frame No. 62500.

+4
source share
2 answers

Therefore, when there are many stack frames, this means that infinite recursion occurs. I assume that when creating the D object, there is some code that automatically creates something else, which in turn creates another D, and there is a loop that is not destroyed. I would start by checking all key value observers or NSManagedObject Overrides

+9
source

It looks like you need to save a new object. The description of this method states that the returned object is auto-implemented, which means that your object is likely to be released before you have a chance to use It. Change your code like this:

 id dto = [[NSEntityDescription insertNewObjectForEntityForName:@"A" inManagedObjectContext:context] retain]; NSLog(@"DTO: %@", dto); 

Be sure to release your object when you're done with it to avoid memory leaks. If you are done with the object (or if it will be saved by another object) by the time dto goes beyond the scope, you can autodetect it so that the autorelease pool takes care of this for you:

 id dto = [[[NSEntityDescription insertNewObjectForEntityForName:@"A" inManagedObjectContext:context] retain] autorelease]; 
0
source

Source: https://habr.com/ru/post/1300633/


All Articles