1
votes

I am working on this issue for a long time and can not get an answer, hope someone can help me out.

I have a ios ARC based app. It's strange that I got "[Not A Type class]: message sent to deallocated instance" from the below code only in iphone then the app just crashed, although it is working well in the simulator. I understand that it could be memory issue, but can not figure out why. After searching the forum, it seems it's related to CGColorRef, but I can not find the simliar case.

self.backgroundColor =  CMConstants.greyColor;
CGContextRef context = UIGraphicsGetCurrentContext();
CGColorRef separatorColor = [UIColor colorWithRed:12/255.0 green:12/255.0 blue:12/255.0     alpha:1.0].CGColor;
CGRect paperRect = self.bounds;
1
can you provide few more details. It is not clear with above lines, problem might reside at some other place as well.Tarun

1 Answers

3
votes

That's because the UIColor is released after the call to colorWithRed:green:blue: because not used and it's causing your CGColorRef to not have any backing.

Do this:

CGColorRef separatorColor = CGColorRetain([UIColor colorWithRed:12/255.0 green:12/255.0 blue:12/255.0     alpha:1.0].CGColor);

And when you're done:

CGColorRelease (separatorColor);