简体   繁体   中英

Iphone app crash when releasing CGColorSpaceRef

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.

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 SIGABRT s 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.

You are actually responsible for retaining and releasing the color space if/as necessary! Ie 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM