Mountain Lion garbage collection/memory problems

I have a project running under Lion (10.7.8) and Xcode 4.3.3 and everything is running perfect.

Now I want to use the project under Mountain Lion and Xcode 4.4 , but I am getting problems with the garbage collection (see errors):

ScriptsLauncher2011(487,0x7fff7215b180) malloc: *** auto malloc[487]: error for object 0x400fdf160: resurrection of thread local garbage belonging to another thread

ScriptsLauncher2011(487,0x7fff7215b180) malloc: resurrection error for object 0x400fdf160 while assigning {conservative-block}320[0] = {uncollectable-memory}(0x400fdf160)
garbage pointer stored into reachable memory, break on auto_zone_resurrection_error to debug

This is the reported issue in Xcode

libobjc.A.dylib`objc_msgSend_vtable4:
0x7fff86c00540: testq %rdi, %rdi
0x7fff86c00543: je 0x7fff86c0055b ; objc_msgSend_vtable4 + 27
0x7fff86c00545: testl $1, %edi
0x7fff86c0054b: jne 0x7fff86c0055f ; objc_msgSend_vtable4 + 31
0x7fff86c0054d: movq (%rdi), %rax
0x7fff86c00550: movq 24(%rax), %rax ------------------>Thread 1: EXC_BAD_ACCESS(code=1, address=0xfffffffbfe9bc217)
0x7fff86c00554: movq 8(%rsi), %rsi
0x7fff86c00558: jmpq *32(%rax)
0x7fff86c0055b: xorl %eax, %eax
0x7fff86c0055d: ret
0x7fff86c0055e: nop
0x7fff86c0055f: movl %edi, %eax
0x7fff86c00561: andl $15, %eax
0x7fff86c00564: leaq 1129437(%rip), %r10 ; __44-[ICDeviceBrowser setBrowsedDeviceTypeMask:]_block_invoke_0 + 755
0x7fff86c0056b: movq (%r10,%rax,8), %r10
0x7fff86c0056f: movq 24(%r10), %rax
0x7fff86c00573: movq 8(%rsi), %rsi
0x7fff86c00577: jmpq *32(%rax)
0x7fff86c0057a: nopw (%rax,%rax)

I have read the document "Garbage Collection and ARC ” managing memory " from Shane and the option : GCC_ENABLE_OBJC_GC : required is set properly.
in this project I am also using the Myriad helpers from Shane.

This problem occurs unexpectedly and cannot really be reproduced.

I hope somebody can help find a way to get rid of this issue.

Thanks,

Have you checked that ARC is off? Can you add some logging to see where it’s happening?

The application uses a timer that triggers every x secs.
The main window contains a table view and the contents are updated whenever the system needs to.
Ik have a text color value transformer for the text in the the rows written in ASOC :


script ColorValueTransFormer
	property parent : class "NSObject"
	
	on transformedValueClass()
		return current application's NSColor's class
	end transformedValueClass
	
	on allowsReverseTransformation()
		return false
	end allowsReverseTransformation
	
	on transformedValue_(theState)
		try
			set cmykGreen to getCMYKColor_({1.0, 0.0, 1.0, 0.2, 1.0})
			set cmykRed to getCMYKColor_({0.0, 1.0, 1.0, 0.0, 1.0})
			set cmykBlue to getCMYKColor_({0.87, 0.6, 0.0, 0.0, 1.0})
			set cmykBrown to getCMYKColor_({0.3, 0.54, 1.0, 0.27, 1.0})
			set cmykOrange to getCMYKColor_({0.0, 0.41, 0.94, 0.0, 1.0})
			set cmykGray to getCMYKColor_({0.25, 0.19, 0.19, 0.0, 1.0})
			
			set theColor to cmykOrange --current application's NSColor's orangeColor
			set theState to theState as boolean
			if theState then
				set theColor to cmykBlue --current application's NSColor's blueColor
			else
				set theColor to cmykOrange --current application's NSColor's grayColor
			end if
			return theColor
		on error errmsg
			return current application's NSColor's grayColor
		end try
	end transformedValue_
	
	on getCMYKColor_(colorlist)
		set cmykColor to current application's NSColor's colorWithDeviceCyan_magenta_yellow_black_alpha_(item 1 of colorlist, item 2 of colorlist, item 3 of colorlist, item 4 of colorlist, 1.0)
		return cmykColor
	end getCMYKColor_
end script

After many tests, i got this error message:
objc[7605]: garbage collection is ON
fatal resurrection error for garbage block 0x401646220(NSDeviceCMYKColor[64]): over-retained during finalization, refcount = 1

After removing the text coloring, the application could run OK.

As an experiment I wrote the transformer in Objective C to see if the same problem occurs. But that works just fine.

So I think that the updating of the table contents bound to a text color transformer written in ASOC could be the problem.

Here is the Objective C code:


@interface SLColorValueTransformer : NSValueTransformer {
	
}

+ (Class)transformedValueClass;
+ (BOOL)allowsReverseTransformation;
- (id)transformedValue:(id)value;

@end

#import "SLColorValueTransformer.h"

@implementation SLColorValueTransformer

+ (Class)transformedValueClass;
{
    return [NSColor class];
}

+ (BOOL)allowsReverseTransformation;
{
    return YES;   
}

- (id)transformedValue:(id) value;
{
    //NSLog(@"the value - %d",[value intValue]);
    int valueInt =  [value intValue];
    
    if (valueInt == 0) {
        return [NSColor orangeColor];
    }
    else if (valueInt  == 1) {
            // return [NSColor blueColor];
        return  [NSColor colorWithCalibratedRed:0.1 green: 0.0 blue:0.70 alpha: 1.0];
        }
    else if (valueInt  == 2) {
        return [NSColor brownColor];
    }
    else  {
        return [NSColor grayColor];
    }
}

- (id)reverseTransformedValue:(id)value
{
	//int valueInt = [value intValue];
	//NSNumber * valueNumber = [NSNumber numberWithInt];
	//return valueNumber;
    return nil;
}

@end

I hope this is the problem, but that is strange as the same code runs OK under Lion (10.7.8 and Xcode 4.3.3).

Thanks Shane for your reaction. BTW, are you going to update the Myriad Helpers to work with ARC under 10.8? That should help us continue using your code (which is very helpful!!)

I have an ARC version, but I didn’t figure that many people would be writing 10.8-only stuff just yet, so checking it has been a low priority. And I gather I should be able to make it handle either. But I’m chasing other nasty demons at the moment…

thanks Shane,

It’s the waiting worth!!!