Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (id)init
- {
- self = [super init];
- if (self != nil)
- {
- [self schedule:@selector(updateMemory:) interval:0.1];
- }
- return self;
- }
- - (void)updateMemory:(ccTime)dt
- {
- static long allocated = 0;
- static void* allocatedPtr = NULL;
- static long size = 1024*1024;
- //NSLog(@"Ticking...");
- allocated = allocated + size;
- if (allocatedPtr)
- {
- free(allocatedPtr);
- }
- allocatedPtr = malloc(allocated);
- if (!allocatedPtr)
- {
- NSLog(@"out of memory at %ld", allocated);
- NSLog(@"%@", [self formatMemory:allocated]);
- [self unschedule:@selector(updateMemory:)];
- [self loadMainMenuScene:0];
- return;
- }
- for (long i=0; i<allocated; i += 4096)
- {
- *(char*)(allocatedPtr + i) = 'a';
- }
- if (allocated > 40*1024*1024)
- {
- NSLog(@"Reached %ld. Terminating memory ballooning", allocated);
- [self unschedule:@selector(updateMemory:)];
- free(allocatedPtr);
- [self loadMainMenuScene:0];
- return;
- }
- }
Add Comment
Please, Sign In to add comment