memory-management

Memory management within a message

Take the line [angleLabelInRadians setText:[[NSString alloc] initWithFormat:@"%.3g", [poly angleInRadians]]]; When creating an NSString object within a message, do I still need to release this NSString and, if so, how would I do that, given that I haven't created a pointer to the object? Furthermore, is this correct coding procedure...

.NET compact framework and memory management: OOM Exception

My .NET CF 3.5 application receives an Out of memory exception when DOM processing an xml file of size 2MB. Now I understand that this should be changed to SAX processing, but I was wondering why this error is received. From http://blogs.msdn.com/b/mikezintel/archive/2004/12/08/278153.aspx, "Windows CE creates one additional virtual ad...

Objective C memory management

The following code is on apple's website. 1) Inside the setMyArray method, is it necessary to release myArray before setting a new value to it? I thought setting the value of an object to a new object, will release the old object from memory. 2) why does it say myArray = [newArray mutableCopy];, instead of simply saying myArray = newAr...

my app works fine on Debug Build gets "BAD ACCESS" on Release Build

my app is working on 128mb idevices when i build with Debug configuraion, but when i build in Release configuration the app crashes on startup with "BAD ACCESS". on 256mb and up it works on both configurations. according to "Activity Monitor" the "Real Memory" usage is 14mb and "Virtual Memory" is 75mb (is this normal?) "Allocations" ...

glibc detected - double free or corruption

Hi friends, this might be a bit long so my apologies. consider the following code (i've left some irrelevant parts from it). this code receives a pointer to a struct (BoardP theBoard), x & y coords and a value. the goal is to place the value in a 2D array that is found in the struct. if the coords are out of bounds, i have to increase th...

Have I managed the memory correctly here? (simple C++ stack)

I'm a complete noob with dynamically allocated memory. Will this have a memory leak or any other memory problem? #include <iostream.h> template <class T> class stack { struct node { T value; node* next; }; public: stack() { ...

Cannot figure out why my object is getting deallocated

I have an NSDate object which I use in the main thread of my iPhone app and I also reference it from a background thread, its defined like this: //header NSDate *currentDate; @property (nonatomic, retain) NSDate *currentDate; //implementation file @synthesize currentDate; Then in my app, I call a refreshData method which passes that ...

warning: check_safe_call: could not restore current frame

i searched over internet but did not get suitable solution of this error Here I'm posting code that i made. My application captures near 200 questions form sqlite db and then creates screen shot of them for slideshow. Application crashes when app captures near 86-87 questions via UIGraphicsBeginImageContext() and fills them into a NSMut...

Should I release the object in this method?

Here is the code: - (id)copyWithZone:(NSZone*)zone { ExecutedOrderInfo* copy = [[self class] allocWithZone:zone]; copy.executedPrice = self.executedPrice; copy.executedQuantity = self.executedQuantity; return (id)copy; } The question is, is it necessary to release "copy" in above code? Or release it when someone called...

Memory management responsibility during inter-thread communication.

If thread A sends a reference to an object to thread B, for example using performSelector:onThread:withObject:waitUntilDone, how should memory management occur? Should the calling thread alloc the object and the called thread release it? EDIT: It turns out that performSelector:onThread:withObject:waitUntilDone retains the object unti...

OpenGL - what does glDeleteTextures actually do?

Hi all, (Mac OS X, iOS apps) Q. What does glDeleteTextures actually do, on the above platforms? (The official documentation is... sparse, at best.) In terms of mem management, do the textures actually get removed from the video card? (Or at least their space set to reusable?) Cheers. ...

Effect of 'myObj = [[[[MyClass alloc] init] autorelease] retain];' ?

I've just downloaded the Facebook iOS SDK and I noticed that in the sample code that comes with the SDK whenever it creates an instance of the Facebook class it does it like this: _facebook = [[[[Facebook alloc] init] autorelease] retain]; where _facebook is a member variable of the calling object (i.e. not a local variable). Can any...

Cocoa - NSDictionary objectForKey - memory management clarification

[I have read the Cocoa memory management rules, but still want to be certain, and would like to know if this is good form.] My class has a mutable dictionary ivar: NSMutableDictionary *m_Dict; ... m_Dict = [NSMutableDictionary dictionaryWithCapacity:10]; [m_Dict retain]; At some point I'll add a mutable array to the dictionary: NS...

My allocated memory is beeing written to

Im writing a project in Objective-C but I'm relying quite much on plain old C since there's OpenGL involved. I have a data blob that I read to memory from a file in the following way: NSString *path = [[NSBundle mainBundle] pathForResource:@"iPadTest" ofType:@""]; NSFileHandle *file = [NSFileHandle fileHandleForReadingAtPath:path]; dat...

jQuery Appending Image Memory Leak?

Coming from flash it was always necessary to drop bitmap data in my slideshows so that I wasn't just loading more and more data into memory and thus weighing the program down. Now that I've started building these slideshows using jQuery, I'm wondering if I should be cognizant of the same issue. For instance, it's easy to keep appendi...

Multiple files downloading using FTP crash only on runtime(not debuging)

I think I have some memory issue with a function that should download a file from ftp server. The reason that I think it's a memory thing is because it works fine during debug (maybe it gives the garbage collector more time). Yet I thought that the using should solve this... Just to be clear the function works when called once yet calli...

Python matplotlib: memory not being released when specifying figure size

I'm using matplotlib to generate many plots of the results of a numerical simulation. The plots are used as frames in a video, and so I'm generating many of them by repeatedly calling a function similar to this one: from pylab import * def plot_density(filename,i,t,psi_Na): figure(figsize=(8,6)) imshow(abs(psi_Na)**2,origin =...

iphone - find out retain counts of variables

Hi there. I don't have any problems with my iphone app. Theres no exc_bad_access or memory issues. However I know that I haven't properly allocated and released memory. I don't know why this isn't throwing any exceptions, but it isn't. Everything works. I don't want to overload the iphone memory though, and am aware that just because I...

Marshalling between C# and C++, and the Juggling of Responsibilities

Hello everybody, what if I had a native C++ function in which, depending on the result of the function, the responsibility of deleting a certain pointer (delete[]) differs between the caller and the function. I would of course check for the return value and act accordingly in C++. Question is, what if the function was marshalled between...

Correct way to instantiate NSDictionary/NSArray in init without extra retains

I have numerous classes that use the various NSDictionary/NSArray collection classes as ivars but often I run into the problem of my collection class getting released before the containing class is released. This seems to happen mostly with the collections classes and not with another model class (ie classes that I either created separ...