Question

I am using CGColorSpaceRef and when i release it, its crash. The Way i creates it and release

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

After doing some task and then release

CGColorSpaceRelease(colorSpace);

error shown by compiler is "Assertion failed: (!state->is_singleton), function color_space_state_dealloc, file ColorSpaces/CGColorSpace.c, line 127" And strange thing is happend when i not release colorspace or just set to nil its work fine, I don't know why this happen. Please help me on this. Thanks in Advance. Have a happy day.

Was it helpful?

Solution

It looks like you have over released the colorspace object. I have just run the following program and I get the error message you quoted.

int main(int argc, char *argv[]) {
    @autoreleasepool {
        CGColorSpaceRef colorspace = CGColorSpaceCreateDeviceRGB();

        CGColorSpaceRelease(colorspace);
        CGColorSpaceRelease(colorspace);
    }
}

This SIGABRTs with the following error:

Assertion failed: (!state->is_singleton), function color_space_state_dealloc, file ColorSpaces/CGColorSpace.c, line 127.

If I only call CGColorSpaceRelease once the program compiles and runs without error.

The static analyser (Shift-Cmd-B) may well be able to show you were you've gone wrong. It certainly flags the above code with "Reference counted object is used after it is released" on the second CGColorSpaceRelease call.

OTHER TIPS

You are actually responsible for retaining and releasing the color space if/as necessary! I.e. if you need to, retain it. If you don't need to retain, don't release! See the docs for more on this topic: Memory Management Programming Guide for Core Foundation

Update:

Regarding the wired error our poster enecountered above, take a look at ddopsons posting here. Unfortunately there's no solution provied, but a possible workaround instead.

You are trying to release a constant value. Cant do that

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top