Why downloading more than one megabyte of images consumes all my iPhone memory?

I am writing an application that should contain about forty-44 kb JPEG in memory at once. I heard that applications can use about 22 megabytes before triggering a low memory warning, so I'm sure he can do it. However, as soon as I go through the downloaded megabytes, these messages begin to appear in the console:

Mon Jun 8 16:37:19 unknown configd [21]: kernel memory event (90), free: 374, active: 1736, inactive: 959, purgeable: 0, wired: 6260
Mon Jun 8 16:37:20 unknown configd [21]: kernel memory event (95), free: 363, active: 876, inactive: 492, purgeable: 0, wired: 6241
Mon Jun 8 16:37:20 unknown SpringBoard [22]: Memory level is critical (5%). No apps to kill. Will kill SpringBoard
Mon Jun 8 16:37:24 unknown SpringBoard [22]: Jetsaming SpringBoard ...

Then it brings me back to the main screen.

Here is the code I use to upload images:

#define NUM_IMAGES 40

@interface MyClass : NSObject {
    UIImageView* imageView;
    UIImage* loadedImages[NUM_IMAGES];
}

- (void)initImages;

@property (nonatomic, retain) IBOutlet UIImageView* imageView;

@end


@implementation MyClass

@synthesize imageView;

- (void)initImages {
    int i;
    for (i = 0; i < NUM_IMAGES; i++) {
        loadedImages[i] = [UIImage imageNamed:[NSString stringWithFormat:IMAGE_FORMAT, i+1]];
    }
    imageView.image = loadedImages[0];
}

@end

Am I doing something wrong here? Can iPhone apps use only megabytes of memory?

+3
source share
2 answers

When you upload a compressed image, such as a JPEG image, it usually does not compress (since this is what you need to do so that you can do something useful with the image, for example, display or manipulate it).

, , , 44 KiB, JPEG ( 3 4 , ). , JPEG.

JPEG ( , ), , .

, , . ? , ( ), ? , ( )? .....

+15

imageNamed: . , , imageWithContentsOfFile:, , " " .

. SO UIImageName: FUD

, :

[UIImage imageWithContentsOfFile:[[UIBundle mainBundle] pathForResource:@"filename" ofType:@"jpeg"]];
+1

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


All Articles