UIButton setBackgroundImage consumes a lot of memory

I am using the following code:

UIImage *buttonImage;

if (p.placeImage != nil) {
    buttonImage = [UIImage imageWithData:p.placeImage];
} else {
    buttonImage = [UIImage imageNamed:@"bg_place_noimg.png"];
}

[imageButton setBackgroundImage:buttonImage forState:UIControlStateNormal];

When I run the application with tools, I see that setBackgroundImage is consuming a lot of memory. However, if I comment on the last line, this will not happen. Any possible reason?

EDIT:

If p.placeImage == nil and imageNamed: @ "bg_place_noimg.png" are used, normal memory usage is used. p.placeImage is the converted value that I use in Core Data to store NSData images downloaded from the Internet.

+3
source share
2 answers

, , . , , , , . , UIImage 0, ​​.

imageWithData imageNamed . UIImage.

+1

, , , imageWithData: , imageNamed: .

. , , URL- URL-.

0

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


All Articles