objective c - iOs memory stress test -
i'm trying simulate behaviour of component under heavy memory load.
the main idea allocate bunch of memory, keep resident, work component, no matter do, memory allocate on purpose seem disappear somehow.
after first test using strong nsarray of nsdata chunks (1mb each), tried rougher lower level approach (to prevent arc magic happen):
// somewhere after includes static char *foo[max_chunks]; [...] // function called, checked :) - (void) allocatememorychunks:(int) chunks ofsize:(long) bytes { for(int = 0; < chunks; ++i) { foo[i] = (char *) malloc(bytes); } }
no matter set chunks
, bytes
, long memory can allocated, 'disappears' memory count in xcode , leaves me usual meager 2mb consumed application (i'm talking of allocations in range of 400 chunks of 1024 * 1024 bytes, or 1 chunk of 400 * 1024 * 1024 bytes, what's worth...).
the memory outside reach of arc (i'm using plain c mallocs!) yet, can't see (note same happened when used nsdata , nsarray hold data).
where memory go? forgetting?
thank you!
addendum
for records, arc version of allocatememorychunks is:
- (void) allocatememorychunks2:(int) nchunks ofsize:(long) bytes { self.allocated = [nsmutablearray arraywithcapacity:nchunks]; for(int = 0; < nchunks; ++i) { char *tmpraw = (char *) malloc(bytes); nsdata *tmp = [nsdata datawithbytes:tmpraw length:bytes]; [self.allocated addobject:tmp]; free(tmpraw); } }
with allocated
declared as:
@property (nonatomic, strong) nsmutablearray *allocated;
Comments
Post a Comment