memory-management

Memory management question: does this code has a memory leak?

// ClassA.m NSString *strA = [[NSstring alloc] initWithString:@"test string"]; ClassB *classB = [[ClassB alloc] init]; [classB setStrB:strA]; [strA release]; // classB will be released later // ClassB.h @property (nonatomic, retain) NSString *strB; // ClassB.m // custom setter -(void) setStrB:(NSString *)newStr { strB = newStr...

.NET Memory Consumption Question

Does either of these methods use more memory than the other or put a larger load on GC? Option #1 LargeObject GetObject() { return new LargeObject(); } Option #2 LargeObject GetObject() { LargeObject result = new LargeObject(); return result; } ...

Memory Leak in a Java based application

There is a memory leak happens in an application when a short lived object holds a long lived object, My question is how can we identify 1) which object lives longer and shorter, any tool which measures life of an object? 2nd Question I am constantly getting the Out of Memory Space Error and I tried increasing the Heap memory to 2 GB...

iphone/ipad troubleshooting device crashes due to memory

I have an app that often crashes on the device (iPad), but not on the simulator, so any simulator debug tactics (MallocStackLogging for example) are not an option. What I usually get in the console is this: Received memory warning. Level=1 Received memory warning. Level=2 Program received signal: “0”. Data Formatters temporarily unavai...

Deleting C++ pointers to an object

I thought that the delete command would free up memory I allocated. Can someone explain why it seems I still have the memory in use after delete? class Test { public: int time; }; int main() { Test *e; e = new Test; e->time = 1; cout << e->time << endl; delete e; e->time = 2; cout << e->time << endl;...

Autorelease pools in appkit applications

I'm having difficulties to understand exactly WHEN autorelease pools are created and released in AppKit apps. For example, if I have an ApplicationController class that overrides init, is there an autorelease pool that gets created before it starts and gets drained after it ends? ...

Windows Mobile Application structure recommendations

I need to create Solution Architechure for Windows Mobile and have following queries: My application is like a service that will start in phone startup and that should run in background and have no UI (this is not a problem). I am using third party dlls (with source code) in my project. Does windows mobile have any problem of loading dl...

CGImageRef Leak.

Maybe this a newbie question, but according to my instruments there is a leak there, but im releasing the imageRef. i cant figure it out. its a category function. -(UIImage *)imageAtRect:(CGRect)rect { CGImageRef imageRef = CGImageCreateWithImageInRect([self CGImage], rect); UIImage* subImage = [UIImage imageWithCGImage: imageRef]; CG...

What does this error mean, and how do I resolve it? (java.lang.InternalError: Memory Pool not found)

We're getting a very curious error in our application. java.lang.InternalError: Memory Pool not found for ( final MemoryPoolMXBean bean : ManagementFactory.getMemoryPoolMXBeans() ) { final MemoryUsage usage = bean.getUsage(); // Error thrown on this line System.out.println(usage); } What does this error mean, and how do I resol...

iphone - change pointer reference to a new object and clean old

NSMutableArray *myArray = [[NSMutableArray alloc] init]; MyClass *obj1 = [[MyClass alloc] init]; [myArray addObject: obj1]; How to clean the old obj1 reference here, if I want to reuse the variable name. Without destroying anything in the array. obj1 = nil OR [obj1 release]; // What is the differences? obj1 = [[MyClass alloc] in...

Memory mapped files performance - memory management when working with large data sets

I have a situation where I need to work with a number (15-30) of large (several hundreds mb) data structures. They won't fit into memory all at the same time. To make things worse, the algorithms operating on them work across all those structures, i.e. not first one, then the other etc. I need to make this as fast as possible. So I figu...

Dynamic Memory Handling Java vs C++

I am a C++ programmer currently trying to work on Java. Working on C++ I have an habit of keeping track of dynamic memory allocations and employing various techniques like RAII to avoid memory leak. Java as we know provides a Garbage Collector(GC) to take care of memory leaks.So while programing in Java should one just let go all the who...

Some questions on how code may influence the GC process

Hi, 1) Does adding a Dispose(), or finalize method, have any impact on making an object be GC'd soon? I ask this as my manager wrote some code, adding a finalize() method, in the hope it would be GC'd. But I argued that the object has to be "marked" for collection first, if it meets certain criteria. 2) Does writing "o = null" (where ...

return type of who_user in scilab

greetings and apologies if this is a repost (i searched this site, and i believe its not a repost, though) I work with scilab, but during a project, scilab has to deal with a large number of variables. I was wondering if i can do the following var_list = who_user(); for _var_ = var_list do if _var_ is global then writetofile(huma...

Memory Management with UINavigationController inside Modal View Controller

Hi all, I am trying to display a modal view controller containing a NavigationController. I can't figure out where to release the controllers, though. Normally, I would just release the controller after displaying it, but that won't work here; presumably that has something to do with the navigation controller. Any help would be great...

Deleting pointers in a vector

Hi, I have a vector that I fill with pointers to objects. I am trying to learn good memory management. I have a few general questions: Is it true that when I am done with the vector I must loop through it and call delete on each pointer? Why don't I have to call delete on the vector (or any other variable I declare without the new stat...

When using autorelease, when is it actually released?

Sometimes I wonder when something gets autoreleased. I added an NSLog in the dealloc of various objects, but I couldn't find anything useful. When does something release when autorelease is used? Is it unpredictable, or is there some extra thread running? Thanks. ...

C++ object created with new, destroyed with free(); How bad is this?

Hello, all. I am working on modifying a relatively large C++ program, where unfortunately it is not always clear whether someone before me used C or C++ syntax (this is in the electrical engineering department at a university, and we EEs are always tempted to use C for everything, and unfortunately in this case, people can actually get ...

When to release an instance variable

Basically I have this scenario going on: //in interface header @property(nonatomic,retain)OtherClass *otherClass; //implementation - (id)initWithOtherClassInstance:(OtherClass*)otherClass { if (self != [super init]) return self; self.otherClass = otherClass; return self; } - (void)dealloc { //Do I need...

Releasing a delegating object in its delegate callback method

I'm trying to figure out what the recommended practice is for the following situation. Certain objects, such as CLLocationManager or MKReverseGeocoder, send their results asynchronously to a delegate callback method. Is it OK to release that CLLocationManager or MKReverseGeocoder instance (or whatever class it may be) in the callback met...