• 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
garbage collection and pointer to object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

garbage collection and pointer to object


  • Subject: garbage collection and pointer to object
  • From: Michael Link <email@hidden>
  • Date: Thu, 21 May 2009 16:17:25 -0500

I have a class with the following methods

- (void)save
{
	NSError* error = nil;

	if (![self save:&error]) {
		NSLog(@"caught error during save: %@", error);
	}
}

- (BOOL)save:(NSError**)error
{
	if (![_thread isCancelled]) {
		return [_managedObjectContext save:error];
	}

	return YES;
}

When -save is called it calls -save: to get error information if an error occurs while saving an NSManagedObjectContext. When an error does occur sometimes a crash will occur at NSLog when trying to get the NSError description. Is it possible that the local variable error in -save is being garbage collected before NSLog is called?

Thread 0 Crashed:
0 com.apple.CoreFoundation 0x00007fff833bd24a CFBundleCopyLocalizedString + 90
1 com.apple.CoreFoundation 0x00007fff833db111 _CFErrorCreateLocalizedDescription + 273
2 com.apple.Foundation 0x00007fff81f0f3f8 -[NSError localizedDescription] + 136
3 com.apple.CoreFoundation 0x00007fff833db25a CFErrorCopyDescription + 138
4 com.apple.CoreFoundation 0x00007fff833db2b4 _CFErrorCreateDebugDescription + 36
5 com.apple.Foundation 0x00007fff81f0f349 -[NSError description] + 9
6 com.apple.Foundation 0x00007fff81e83770 _NSDescriptionWithLocaleFunc + 128
7 com.apple.CoreFoundation 0x00007fff83428b54 _CFStringAppendFormatAndArgumentsAux + 2964
8 com.apple.CoreFoundation 0x00007fff83429fa8 _CFStringCreateWithFormatAndArgumentsAux + 120
9 com.apple.CoreFoundation 0x00007fff8345dab0 _CFLogvEx + 64
10 com.apple.Foundation 0x00007fff81e9ba0b NSLogv + 139
11 com.apple.Foundation 0x00007fff81ef69a2 NSLog + 162
12 net.fractal.Bug 0x0000000100094d74 0x100000000 + 609652
13 net.fractal.Bug 0x0000000100050e58 0x100000000 + 331352
14 com.apple.CoreFoundation 0x00007fff8347dead __invoking___ + 141
15 com.apple.CoreFoundation 0x00007fff8347d774 -[NSInvocation invoke] + 148
16 net.fractal.Bug 0x0000000100040b6d 0x100000000 + 265069
17 com.apple.CoreFoundation 0x00007fff8347dead __invoking___ + 141
18 com.apple.CoreFoundation 0x00007fff8347d774 -[NSInvocation invoke] + 148
19 com.apple.CoreFoundation 0x00007fff8347d833 -[NSInvocation invokeWithTarget:] + 51
20 com.apple.Foundation 0x00007fff81e7f754 __NSThreadPerformPerform + 148
21 com.apple.CoreFoundation 0x00007fff83404008 CFRunLoopRunSpecific + 2808
22 com.apple.HIToolbox 0x00007fff82a71bce RunCurrentEventLoopInMode + 278
23 com.apple.HIToolbox 0x00007fff82a71963 ReceiveNextEventCommon + 161
24 com.apple.HIToolbox 0x00007fff82a718af BlockUntilNextEventMatchingListInMode + 79
25 com.apple.AppKit 0x00007fff80a89420 _DPSNextEvent + 603
26 com.apple.AppKit 0x00007fff80a88d61 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 136
27 com.apple.AppKit 0x00007fff80d07457 -[NSScrollView scrollWheel:] + 721
28 com.apple.AppKit 0x00007fff80be9d59 forwardMethod + 100
29 com.apple.AppKit 0x00007fff80d0716e -[NSView scrollWheel:] + 249
30 com.apple.AppKit 0x00007fff80be9d59 forwardMethod + 100
31 com.apple.AppKit 0x00007fff80d0716e -[NSView scrollWheel:] + 249
32 com.apple.AppKit 0x00007fff80b5b40b -[NSWindow sendEvent:] + 6820
33 com.apple.AppKit 0x00007fff80b282f6 -[NSApplication sendEvent:] + 5089
34 com.apple.AppKit 0x00007fff80a82b20 -[NSApplication run] + 499
35 com.apple.AppKit 0x00007fff80a4f8ac NSApplicationMain + 373
36 net.fractal.Bug 0x00000001000096fb 0x100000000 + 38651
37 net.fractal.Bug 0x00000001000021b8 0x100000000 + 8632


Thread 1:
0 libauto.dylib 0x00000001006876e4 Auto::Admin::deallocate(void*) + 772
1 libauto.dylib 0x000000010068e623 Auto::Zone::block_deallocate_internal(void*) + 355
2 libauto.dylib 0x000000010067c1cd auto_collect_internal(Auto::Zone*, unsigned int) + 2685
3 libauto.dylib 0x000000010067c380 auto_collection_thread(void*) + 112
4 libSystem.B.dylib 0x00007fff827ade8b _pthread_start + 316
5 libSystem.B.dylib 0x00007fff827add4d thread_start + 13



-- Michael _______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: garbage collection and pointer to object
      • From: Mike Abdullah <email@hidden>
  • Prev by Date: Re: Question about notifying KVO observers of changes to a property.
  • Next by Date: Re: Privilege elevation of a cocoa app
  • Previous by thread: Re: Question about notifying KVO observers of changes to a property.
  • Next by thread: Re: garbage collection and pointer to object
  • Index(es):
    • Date
    • Thread