memory-management

Property attribute "retain" doesn't seem to be working?

I've implemented a bit of code from one of the many Apple code examples, but I'm having a bit of trouble, because the retain attribute of one of the properties doesn't appear to be working. Here's the property declaration: @property (nonatomic, retain) EditingViewController *editingViewController; And here's the code: - (EditingViewC...

AS3: Optimizing Object Memory Size

I have have a class that I wrote, and it seems bigger than it should be. It doesn't extend anything, and has very little going on - or so I thought - but each one is taking up just under 100k100 bytes ( thanks back2dos ). I guess that I don't have a very good understanding of what really affects how much memory an object takes up in AS3...

Testing memory usage which tool?

Currently we are using Rational Purify, however it is a pain to use and we have now reached the stage where we are unable to instrument our applications without changing our development build system. The our application is statically linked and large. It is also memory hungry, where peak memory usage is often over 3Gb. Ideally I would ...

Retaining an object created in an NSThread

I have the following method which is spawned by a call for a new thread (using NSThread): - (void) updateFMLs { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSArray *temp = [[NSArray alloc] initWithArray:someArrayFromAnotherProcess]; [self performSelectorOnMainThread:@selector(doneLoading:) withObject:temp...

How do I force a program to appear to run out of memory?

I have a C/C++ program that might be hanging when it runs out of memory. We discovered this by running many copies at the same time. I want to debug the program without completely destroying performance on the development machine. Is there a way to limit the memory available so that a new or malloc will return a NULL pointer after, sa...

iPhone crashes when I "properly" release pushed view controllers

I have a navigation controller based application and I'm running into a strange issue where a few of my view controller pushes are causing crashes upon "popping" the view controller. I've narrowed it down to the line of code that releases the view controller after pushing it on the navigation controller's stack. My code looks like this...

Is it worth mitigating against the effects of garbage collection?

I have an application where the memory profile looks something like this: The slow upwards crawl of memory usage is caused by the allocation of lots and lots of small, simple, transient objects. In low-memory situations (This is a mobile app) the GC overhead is noticeable when compared to less restrictive memory amounts. Since we kno...

Is a thread's stack reported as memory used in Task Manager?

My coworkers and I are trying to track a memory issue in an application, and in my research I found a blog entry that talks about how each thread gets a 1MB stack by default. Our application happens to create a lot of threads, and so we wrote a quick test program to make sure we understood exactly what was happening. The test app (C#) ...

shared objects within a struct: between a calling program and library (in c)

Hi, In a separate library, we have a struct with: typedef struct bsmat{ int m; int *n; double **d; } bs; where **d is a array of pointers to double arrays. bs *new_bs(int n, double **d); There are two use cases: (a) The main application allocates multiple double matrices and calls the library to construct the structure. b = new...

iPhone Memory Leak JSON Library

I'm getting an instruments Memory Leak with this iPhone 3.0 SDK code. I'm using the JSON from http://code.google.com/p/json-framework/ Here is my code: // .h @property (nontatomic,retain) NSMutableArray *tweets; // .m import" JSON.h" @synthesize tweets; ... tweets = [[NSMutableArray alloc] init]; NSURL *url = [NSURL URLWit...

How do I set these break points in ~/.gdbinit?

Here is a list of break points to put in ~/.gdbinit that are really helpful in debugging memory problems: fb -[NSException raise] fb -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] fb -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] #define NSZombies # this will give you help me...

Is it possible to 'see' the object graph for garbage collection?

I have a Java application that is leaking memory. I know which objects are not being freed during garbage collection, but I can't work out what is referencing them. Is it at all possible to have some sort of visibility of the object graph that is being held internally by the JVM? It is at all otherwise possible to find out which object...

Memory usage when files are loaded via mmap()

Hi, Wanted to know what if there is a relationship between the maximum amount of memory that can be used to map a file through mmap() and the size of the RAM in a linux box. I tried to memory map some files , and I found that I am not able to map any more files when the "Mapped" usage comes close to the "MemTotal" ( viewed via cat /proc...

Best way to implement a dynamic stack type? or Am i abusing realloc?

I'm using an obscure language that doesn't have a native stack type so I've implemented my own. Now, reading on the net i've found a few different approaches to do this. This is my implementation (psuedo code) //push method function Push(int) { Increase (realloc) stack by 4 bytes; Push int into the new memory area; } //pop met...

How do I release self (UIImageView) in touchesEnded?

I have an object that is a child of UIImageView. Before all these touches methods, I add this object to the superview and then user moves it. In touchesEnded, sometimes I want to release self. I've tried: - [self release] or - [self removeFromSuperview] But all these tries end up in exceptions. What's the right way to release self...

NSDate init question, related to memory management in Objective-C

I have an NSDate object created by NSDate *date = [[NSDate alloc] init]; Later, I want to reset the date to the "now", so I thought that [date init]; or date = [date init]; might do the job, but they don't. Instead, [date release]; date = [[NSDate alloc] init]; works. I'm a bit confused about this, since in the documentation ...

C : Why do you specify the size when using malloc?

Take the following code : int *p = malloc(2 * sizeof *p); p[0] = 10; //Using the two spaces I p[1] = 20; //allocated with malloc before. p[2] = 30; //Using another space that I didn't allocate for. printf("%d", *(p+1)); //Correctly prints 20 printf("%d", *(p+2)); //Also, correctly prints 30 //although I did...

Is there different about the following memory allocation?

There are four ways to dynamic allocate memory, is there differences among the four ways? first like this: char *seq=(char *)malloc(100*sizeof(char)); void exam(char *seq){ // using 'seq' } second like this: char *seq; void exam(char *seq){ seq=(char *)malloc(100*sizeof(char)); // using 'seq' } third like this: char *s...

In Perl, how can I release memory to the operating system?

I am having some problems with memory in Perl. When I fill up a big hash, I can not get the memory to be released back to the OS. When I do the same with a scalar and use undef, it will give the memory back to the OS. Here is a test program I wrote. #!/usr/bin/perl ###### Memory test ###### ## Use Commands use Number::Bytes::Human qw(...

How do I convince my colleagues not to implement IDisposable on everything?

I work on a project where there is a huge number of objects being instanced by a few classes that stay in memory for the lifetime of the application. There are a lot of memory leaks being caused with OutOfMemoryExceptions being thrown every now and again. It seems like after the instantiated objects ago out of scope, they are not being g...