memory-management

Safely moving a C++ object

I’ve heard some words of warning against shipping an object to another memory location via memcpy, but I don’t know the specific reasons. Unless its contained members do tricky things that depend on memory location, this should be perfectly safe … or not? EDIT: The contemplated use case is a data structure like a vector, which stores o...

iPhone crashing when presenting modal view controller

Hi there, I'm trying to display a modal view straight after another view has been presented modally (the second is a loading view that appears). - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; // Show load LoadViewController *loader = [[LoadViewController alloc] init]; [self presentModalViewContro...

Python memory leaks?

I am writing a python extension that seems to be leaking memory. I am trying to figure out the soure of the problem using valgrind. However, it seems that python itself is leaking memory according to valgrind. Using the following simple script: hello.py print "Hello World!" and doing > valgrind --tool=memcheck python ./hello.py...

Stack overflow due to heap allocation/deallocation..

EDIT: Just to make things clear, this problem was caused by a typo in my code, in pointer = new BYTE(datasize); should have been pointer = new BYTE[datasize]; All is well! END Hi! I'm having a weird stack overflow problem in Visual Studio 2005 in a C++ project.. In my code, I have a BYTE* pointer; This pointer is set to NU...

Which memory is released by didReceiveMemoryWarning/viewDidUnload?

My iPhone application is running into problems when deployed to the device, principally because I haven't handled memory warnings thus far (no problem in the simulator, with 4GB of ram on my dev machine!). No problem there, I just need to handle these warnings more skilfully (less suckily...). Question is, which memory does the runtime...

My code either leaks and works, or doesn't leak and crashes. This doesn't seem like an autorelease problem...

After I finished coding the difficult parts of my game, I found some memory management bugs. objects is a NSMutableArray holding a custom class. - (void) spawnObjects { for (int index = 0; index < INITIAL_OBJECTS; index++) { [objects addObject:[[[MatchObject alloc] initWithImageNameID:(index % 3)] autorelease]]; ...

iPhone development: pointer being freed was not allocated

Hello, i got this message from the debugger: Pixture(1257,0xa0610500) malloc: *** error for object 0x21a8000: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug so i did a bit of tracing and got: (gdb) shell malloc_history 1257 0x21a8000 ALLOC 0x2196a00-0x21a89ff [size=73728]: thread_a0...

iPhone - UIImage imageScaledToSize Memory Issue

I have done research and tried several times to release the UIImage memory and have been unsuccessful. I saw one other post on the internet where someone else was having this same issue. Everytime imageScaledToSize is called, the ObjectAlloc continues to climb. In the following code I am pulling a local image from my resource directory...

How to completely deallocate a mutable array and then allocate again

Hi, I have a table view, the mutable array pointer itemList holds the objects for its cells. I allocate and init the mutable array, itemList = [[NSMutableArray alloc] init]; and add the objects into the array and the table view is loaded. Now i need to dealloc the whole array and allocate again to hold a new array of objects to be sh...

Preventing Memory issues when handling large amounts of text

I have written a program which analyzes a project's source code and reports various issues and metrics based on the code. To analyze the source code, I load the code files that exist in the project's directory structure and analyze the code from memory. The code goes through extensive processing before it is passed to other methods to ...

Python memory leaks

I have a long-running script which, if let to run long enough, will consume all the memory on my system. Without going into details about the script, I have two questions: Are there any "Best Practices" to follow, which will help prevent leaks from occurring? What techniques are there to debug memory leaks in Python? ...

Collections of collections and Objective-C memory management

I have a pretty simple question. While I am fairly new to Objective-C, I have gotten pretty comfortable with the language and the memory management model. I understand ownership pretty well and the notion of explicit and implicit. I also understand that when you add anything to a collection, it takes ownership of the keys and values a...

How can I determine how much memory my program is currently occupying

Related to my previous question: Preventing Memory issues when handling large amounts of text Is there a way to determine how much memory space my program is occupying? I end up processing a large amount of text file and usually store the processed objects in memory. There are times where there will be too much information, and ...

What's the maximum memory footprint in MB for an typical iPhone app?

I know this is a subjective question. As far as I know, there are somewhat about 25 MB available for the app, but it depends on what else is going on. Currently playing music, a current phone call or what ever might drop that amount of memory down a lot. I don't know. Just tell us what you think, or what you have experienced. My app cur...

The power of .NET without the garbage collection?

I love C# because the powerful features of the .NET framework make it so easy to develop for Windows. However I also love standard C++ primarily because it gives me fine-tuned control over memory management. Is there a way to have the best of both worlds? Are there C++ libraries that can compete with the rich set of libraries in the .NET...

How do you free system ram when creating and disposing user controls.

I have a c# application that is composed of various screens which is each a respective user control. The application requires a lot of switching between the various screens and is also graphic intensive. Each control is disposed once the next control is invoked and the garbage collector is called to release the system resources. The thin...

MATLAB's Garbage Collector?

What is your mental model of it? How is it implemented? Which strengths and weaknesses does it have? MATLAB GC vs. Python GC? I sometimes see strange performance bottlenecks when using MATLAB nested functions in otherwise innocuously looking code, I am sure it is because of GC. Garbage Collector is an important part of VM and Mathworks ...

C++ and process memory protection

I know that WinAPI has built-in hacking functions. I even used them in C# with Pinvoke... To hack Minesweeper... It was easy... So... How i could protect my application from process memory editing, deny DLL injecting and other hacking ways. HOW?! Hope WinAPI has something like void DontTouchMeOrIWillTerminateYou(bool protect)... ...

Why is Instruments reporting custom UITableViewCell code as a memory leak?

I'm still trying to find my way through memory management for the iPhone SDK, and I'm not sure why Instruments is reporting a certain block of code as a memory leak. I've followed tutorials for these parts of the code, so I'm not really sure what I'm doing wrong. The violating block of code: DreamTableCell *cell = (DreamTableCell *)[ta...

iPhone - dealloc subview UIViewController when removeFromSuperview

I have several buttons on my main UIViewController (main menu) that creates and adds a subview UIViewController on top of the main menu. When I remove the subview the memory from that controller is not released. How can I release that subviews memory instantly? Does anyone have an example? This would solve all my problems! Thanks in...