memory-management

for- loop in background thread accesses each index more than once --- iPhone dev

I have a method getImageData which I call as [self performSelectorInBackground:@selector(getImagesData ) withObject:nil]; in my viewDidLoad. getImageData has a for-loop i realised that each index in the loop is called more than once. I also access a static NSMutableArray in the loop. When i don't retain the array it gives me exc bad acce...

Cocoa String Question

I have a NSString and I want to write its value to a NSMutableString. Is this valid: NSString *temp = [NSString stringWithString:@"test"]; NSMutableString *mutable = temp; I ask because although this seems doable, I would think that this would assign both temp and mutable to the same address space. I have this question a lot when pa...

My iPhone Simulator Crashes Everyother Time I Run it

The app will run fine, then crash - literally every other time. It seems like the crash cleans up the memory and clean run corrupts the memory. I assume it has to do with memory allocation but I am not sure. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *MyI...

Objective-C/iPhone memory management question

In my iPhone app, I have a "statistics" view that is displayed by the following method - the method itself is called when the user touches a button. This method is in a UINavigationController - (void) showStatsView { StatsViewController *statsViewController = [[StatsViewController alloc] initWithNibName:@"Stats" bundle:[NSBundle mai...

Sharing objects between C# and C++ code

Is it possible to share references to C# objects between C# and C++ code without massive complexity? Or is this generally considered a bad idea? ...

How can I explicitly free memory in Python?

I wrote a Python program that acts on a large input file to create a few million objects representing triangles. The algorithm is: read an input file process the file and create a list of triangles, represented by their vertices output the vertices in the OFF format: a list of vertices followed by a list of triangles. The triangles a...

What happens behind-the-scenes when I create a new UIImage by assignment?

I am getting errors of type EXC-BAD-ACCESS where I create a new UIImage instance by assigning the value of a pre-existing UIImage (as below) and I am trying to figure out what the problem is. There is a heap of code to sort through and I am not sure where to start so I won't bother posting source -- but it might help me in my investigati...

C memory management beginner question

OK, I have this piece of code: typedef struct faux_crit { char dna[DNALEN+1]; //#define'd to 16 int x, y; int age; int p; int dir; } crit; crit *makeguy(int x, int y) { crit *guy; guy = (crit *) malloc(sizeof(crit)); strcpy(guy->dna, makedna()); guy->x = x; guy->y = y; guy->age = guy->p = guy->dir = 0; return gu...

How can I find the size of the memory referenced by a pointer?

GetMem allows you to allocate a buffer of arbitrary size. Somewhere, the size information is retained by the memory manager, because you don't need to tell it how big the buffer is when you pass the pointer to FreeMem. Is that information for internal use only, or is there any way to retrieve the size of the buffer pointed to by a poin...

Memory usage VS. CPU usage in the iphone

I'm writting a small game in OpenGL, where I represent Items, enemies, characters, ect with a class. Each class saves references to one or more objects from an Animation class. An animation class contains references to one or more frames, which are textures I already loaded using openGL. Whenever I rotate, scale, ect any element in the g...

iPhone memory management Question

Hi , i m new to iPhone programming. i am very confused... plz help .. i have a list of questions. 1. - (void){ ClassOne *ob = [[ClassOne alloc] init]; // do i should use autorelease here ? self.O = ob; [ob release]; // is this correct ?? } or -(void)dealloc{ [O release]; // is this correct ?? } which one will release ob ?...

Is memory cleared by the Linux kernel when brk is reduced then increased again?

I'm just wondering about what happens to memory that a user program releases through a brk system call, then gets back again. Does the kernel clear it out or is the contents left undefined? I believe that the kernel clears out pages when they are newly allocated via brk, but I can't work out if it zeros them all if that page is returned...

Cleaning up Objective-C code

When working on complex problems, I find myself trying all sorts of solutions and, while doing my best to stay organized, the code can get quite messy. Objects may be changed and no longer be of use, while other times I may add snippets of code that do not end up being used by the program but are taking up space and possibly memory. Asi...

Cleaning up ODBC DSN in C# .NET

I am using C# and an OBDC DSN to connect to a Paradox database. I seem to be leaking memory if I open and close each connection. My code is basically: csb.Dsn = "DNSName"; OdbcConnection con = new OdbcConnection(csb.ConnectionString); con.Open(); OdbcCommand comm= new OdbcCommand("SELECT...

Disposing a StringBuilder object

How does one effectively dispose a StringBuilder object? If an user generates multiple reports in a single sitting, my app ends up using a huge amount of memory. I've read in a few sites online that the follow may help: StringBuilder sb = new StringBuilder(1000000); // loop goes here adding lots of stuff to sb exampleObject.Text = sb...

How Can I Empty the Used Memory With Python ?

I have just written a .psf file in Python for executing an optimization algorithm for Abaqus package, but after some analysis it stops. Could you please help me and write Python code to free the memory? Thanks ...

iPhone Memory Leaks

If an application produces a lot of memory leaks, are they "just" an in-app problem or are they also in RAM after the termination of the application? So does the iPhone OS release the memory allocated for the sandboxed application? Thank you ...

Memory Management with NSDecimalNumber: How to avoid memory problems in tight loops?

I have a tight loop that iterates about 500 times. In every iteration, it will create a few NSDecimalNumber objects to do some arithmetics. Example - this code snippet is in the for loop. the -decimalNumberByAdding: method creates a new NSDecimalNumber instance and autoreleases it. resultDecimalNumber = [resultDecimalNumber decimalNumb...

in-place realloc with gcc/linux

Is there such a thing? I mean some function that would reallocate memory without moving it if possible or do nothing if not possible. In Visual C there is _expand which does what I want. Does anybody know about equivalents for other platforms, gcc/linux in particular? I'm mostly interested in shrinking memory in-place when possible (and...

What to do in class specific version of placement new ?

Class-specific version of placement new can be provided even though you can't replace the global one. What scenarios exist where a class should provide its own placement new operator? Even if my class don't implement placement new the following code works (assuming for abc no operator new is overloaded). char arr[100]; abc *pt = n...