i'm trying hold basic information pixel inside object. basically, (1) whether pixel clear , (2) whether pixel on defining surface edge. i'm using following class define object:
@interface pixelinfo : nsobject @property (nonatomic, assign) bool isclear; @property (nonatomic, assign) bool isedge; @end
however, i'm running low memory issues. i'm using object keep track of state of pixel in game has destructible environment. problem may ipad retina sized image (2048 x 1536 = 3 million pixels), creating 3 million of these objects , seems allocating hundreds of mb of memory, , causing iphone device force quit due low memory issues.
looking @ logs inside iphone device, i'm getting following information:
name rpages recent_max [reason] (state) myapp 166400 166400 [per-process-limit] (frontmost) (resume)
using instruments allocations tool, see hundreds of mb of memory being allocated pixelinfo objects on time, until eventually, iphone device force quits.
based on this, i'm guessing maybe should not holding pixel information this. i'm suspicious instruments allocations showing device needing hundreds of mb of memory accomplish this. may going wrong elsewhere, can't seem pinpoint it.
i feel need keep track of state of pixels. i'm using pixel information track state of image when destroying environment (i.e., setting pixel info isclear
property yes, , isedge
property no), recalculate new edges affected portion of environment.
here main questions:
- is bad attempting hold 3 million objects inside array?
- low memory problem (seen using instruments allocations tool), correct hundreds of mb of memory needs used these 3 million objects or else causing issues?
any thoughts or pointers on how should debug situation further helpful. in advance.
-- additional context (if relevant), how reading , storing pixel information texture (using cocos2d classes):
unsigned char data[4]; // create texture read pixel data ccrendertexture *rendertexture = [[ccrendertexture alloc] initwithwidth:widthinpoints height:heightinpoints pixelformat:kcctexture2dpixelformat_rgba8888]; [rendertexture beginwithclear:1 g:1 b:1 a:0]; // self.view ccsprite object , visit method draws texture can read pixels [self.view visit]; (int = 0; < heightinpixels; ++i) { (int j = 0; j < widthinpixels; ++j) { // read pixel data cgpoint pixelpoint = ccp(j, i); glreadpixels(pixelpoint.x, pixelpoint.y, 1, 1, gl_rgba, gl_unsigned_byte, data); // store pixel data in pixelinfo object; read alpha value in data pixelinfo *pixelinfo = [[pixelinfo alloc] init]; pixelinfo.isclear = [self _ispixelclear:data]; // add object _pixeldata array (nsmutablearray object) [_pixeldata addobject:pixelinfo]; [pixelinfo release]; } } // release texture [rendertexture end]; [rendertexture release];
to decrease memory usage, use 2 boolean array instead of array containing instances of objects 2 booleans
Comments
Post a Comment