memory-management

.net OutOfMemory exception

While making some final tests of a class-library that I'm writing for Windows Mobile (using Compact Net Framework 2.0), I ran into an OOM-exception. Basically, my library loads first a dictionary-file (an ordinary text file with a word list) and thereafter another file based upon the dictionary (I call it KeyMap) which size is more or ...

How can I programmatically determine the maximum user-mode space of the (windows) OS ?

I'm writing a diagnostic app which needs to log what the user has set as his user-mode space a.k.a. user-mode virtual address space a.k.a. the /3GB switch in WinXP or the increaseuserva switch in bcdedit on Vista/Win7. Either of C++ or C++/CLI will do. Any ideas ? ...

In Delphi 2009 do I need to free variant arrays?

If I have a variant array which holds nothing but simple types, and possible further variant arrays of simple types, do I need to do anything explicit to free memory, or is it all taken care of for me. I've always thought there is nothing to do, but I just had a slight doubt! ...

How can I securely free up memory by removing UIImageViews from the screen?

I have some UIImageViews that are nested in UIViews, which group them together. They're owned by an view controller. As soon as the -viewWillDisappear method is called, I want to remove those UIImageViews with their UIViews alltogether, so that the memory gets freed up. I call -release on the UIViews that contain the UIImageViews as sub...

Making an NSMutableString transformation without leaking memory?

I have this function within an iPhone project Objective C class. While it's correct in terms of the desired functionality, after a few calls, it crashes into the debugger. So I think it's a case of bad memory management, but I'm not sure where. - (NSString *)stripHtml:(NSString *)originalText { // remove all html tags (<.*>) from the ...

What kind of indicators do I have to look at in Instruments app and ObjectAlloc, to see if I have memory leaks in my app?

I guess that the "# Net" column is the most interesting, although I don't really understand what that's supposed to mean. Total number of currently allocated objects? It changes all the time, even if I don't do anything. Are there any good "rules of thumb" to see if there is an memory leak? ...

Will -replaceObjectAtIndex:withObject: of NSMutableArray release the old object that's replaced by a new one?

The documentation doesn't say anything about that. When an old object is "removed" and a new one comes into it's place, then what happens with the old one? Do I have to release it by myself? ...

presentModalViewController:animated: crash after dismiss (memory mgmt related?)

I'm currently having an issue with UIViewController's presentModalViewController:animated:. I use the following code to set up and show the modal view controller: UINavigationController *navigationController = [[UINavigationController alloc] init]; AddSerialController *serialController = [[AddSerialController alloc] initWithNibName:...

Objective C Memory Management Confusion

I was reading the apple documentation for memory management, and came across something that I just don't understand. Basically, I don't understand why one does not need need to retain an instance variable through the "getter" method. I wrote this little program to see what would happen. I thought there would be a crash, but I am obvio...

Avoiding Initial Memory Heap Size Error

Hi all, I run a Java code with the following command: $ java -Xms4G -Xmx4G myjavacode My cpu's RAM capacity is 6GB. However it always fail to execute giving me this error message: Invalid initial heap size: -Xms5G The specified size exceeds the maximum representable size. Could not create the Java virtual machine Is there any wa...

Why do I have to call super -dealloc last, and not first?

correct example: - (void)dealloc { [viewController release]; [window release]; [super dealloc]; } wrong example: - (void)dealloc { [super dealloc]; [viewController release]; [window release]; } Althoug in alsmost all other cases when overriding a method I would first call the super's method implementation, i...

NSNumber out of scope?

I've written an Objective-C class and I'm using a shared instance of it across several of the views in my iPhone project. Its member variables include bools, ints, NSStrings and one NSNumber. The shared instance seems to work just fine across the scope of my application, except for the NSNumber which the debugger tells me is "out of scop...

How could this C fragment be written more safely?

Hi, I have the following C code fragment and have to identify the error and suggest a way of writing it more safely: char somestring[] = "Send money!\n"; char *copy; copy = (char *) malloc(strlen(somestring)); strcpy(copy, somestring); printf(copy); So the error is that strlen ignores the trailing '\0' of a string and therefore it ...

Are there memory efficiencies gained when code is wrapped in functions?

I have been working on some code. My usual approach is to first solve all of the pieces of the problem, creating the loops and other pieces of code I need as I work through the problem and then if I expect to reuse the code I go back through it and group the parts of code together that I think should be grouped to create functions. I...

iPhone Memory Management didReceiveMemoryWarning

Ok...... I'm implementing a simple OpenGL ES application on the iPhone and I recently added in Pinch Media Analytics. Doing this helped uncover a memory management problem, and I'm not entirely sure how to deal with it. In a perfect world, my application - which loads PNGs and .CAF files in didFinishLoading will launch, load all of it...

how do I pass a byte[] reference as the buffer in a System.Net.Sockets.Send().Recieve()

Hi there, I have been reading about the various memory management issues that .NET Asynchronous Sockets have. There are but a handful of links, but spidering this one will get you them all: http://codebetter.com/blogs/gregyoung/archive/2007/06/18/async-sockets-and-buffer-management.aspx Basically when a socket is asynchronously sendin...

What is the proper way to manage memory of a class variable / method in objective c?

I'm learning Objective - C and coming from a garbage collected world. I am creating a class (static) variable of a dictionary and I am unsure if I am doing it properly for memory management or not. I'm using a convenience method so the object should be auto-released, but I don't really know if I need to release or retain it in my class. ...

NSObject release... Still shows up in ObjectAlloc

I have been tracking down why NSObject references, while being explicitly release, still show up in ObjectAlloc. In fact, have reduced down NSObject to a basic shell, with a [[myObject alloc]init] immediately followed by a [myObject release], and it does not look like it is being released in ObjectAlloc. This is a big problem with a Na...

Does NSString stringWithCString: length: retain the byte array I pass in?

I'm working with AsyncSocket where the the AsyncSocket object calls a delegate method below whenever it receives data from remote end: - (void)onSocket:(AsyncSocket*)socket didReadData:(NSData*)data withTag:(long)tag; Now, within this method, I pass the NSData object into the following command to get a NSString representation of the ...

Overwriting vs allocation/deallocation - efficiency

I am writing a C++ application which will require a block of memory (about 1000 bytes) as a temporary buffer for some text processing. The operation may be repeated up to 10,000 times a second. Could anybody confirm that it would be more expensive to allocate the memory each time I need the buffer (i.e. new with a smart pointer, memory ...