UIImage imageNamed, which gives EXC_BAD_ACCESS a second time

I am working on a game with a bunch of mini-games. Inside one game mode, I have the following code:

UIImage* img = [UIImage imageNamed:@"foo.png"];
someImage = CGImageRetain(img.CGImage);
[img release];

someImage is of type CGImageRef, and this is not a problem for the first time. After the user loses the mini-game (or exits), the game and everyone seems to get dealloc'd properly. Then, if they return to the mini-game and the game is built again, the line:

someImage = CGImageRetain(img.CGImage);

causes an error of some kind ... almost like my UIImage object has already been released. I know some quirks use [UIImage imageNamed], but I can't track this at all. Any help would be greatly appreciated :)

+3
source share
1 answer

;

[img release];

Cocoa , copy alloc, .

, , . , ( ) . , .

, . , , , .

Cocoa.

+11

Source: https://habr.com/ru/post/1703468/


All Articles