memory-management

How do I debug weird memory management issues in Xcode/Objective-C?

I'm newish to Objective-C and my memory management skills are not great. However, I haven't had a single problem until now. And now I've got big problems. I've gone from zero crashes to crashing at random points, giving me either no console output or unrecognized selector errors on random types (-[NSCFSet isSameAsStop:]: unrecognized se...

What is the guaranteed lifecycle of -[NSString UTF8String]?

The docs vaguely say that it will stick around as long as needed, but when is it actually deallocated? When the original NSString is deallocated? When the current autorelease pool clears? Sometime else? Furthermore, when is it guaranteed to stay for, as opposed to the current implementation? If it stays for the lifetime of the NSStr...

Navigation Controller and Bar - Memory Managment

Hi! first of all... i'm italian, so i'm sorry for my bad english! so... this is my app: i'm using a navigation controller: in the first view there are 10 buttons and every button calls a functions like this: [self pushViewController:nameview animated:YES]; to a different uiviewcontroller! So i have 11 uiviewcontroller! Every cont...

releasing object after return

Hi, I use an object to get some values with it and return this values. The values which will be returned are still in this object. Heres the code: XMLErrorParser *xmlErrorParser = [XMLErrorParser alloc]; [xmlErrorParser parseData: data]; return xmlErrorParser.errors; So how can i release the xmlErrorParser Object and retu...

Expected segmentation fault, as soon as assigning a value to index 1?

Hello, In the code snippet, I expected a segmentation fault as soon as trying to assign a value to count[1]. However the code continues and executes the second for-loop, only indicating a segmentation fault when the program terminates. #include <stdio.h> int main() { int count[1]; int i; for(i = 0; i < 100; i...

Problem with OpenCL

Hi, I'm facing a problem with OpenCL and I hope someone will have a hint on what the cause might be. Following is a version of the program, reduced to the problem. I have an input int array of size 4000. In my kernel, I am doing a scan. Obviously, there are nice ways to do this in parallel, but to reproduce the problem, only one thread ...

What would a garbage collector do here?

I saw this bit of code in another thread void foo { int *n = malloc(sizeof(int)); *n = 10; n++; printf("%d", *n); } The mistake here is obvious. n isn't being dereferenced. There is a memory leak. Let's assume there is a garbage collector working here. The reference count to our initial value of n is zero now because n isn't...

Ways to reduce memory churn

Background I have a Spring batch program that reads a file (example file I am working with is ~ 4 GB in size), does a small amount of processing on the file, and then writes it off to an Oracle database. My program uses 1 thread to read the file, and 12 worker threads to do the processing and database pushing. I am churning lots and ...

Custom UIView throws a EXC_BAD_ACCESS on [super dealloc]

Hello. I'm developing an iPhone application. I have a class that inherits from UIView. It has a method to add two UILabels and one UIImageView as subviews of the class. The UILabels and UIImageView are created and destroyed on that method. When I release this custom class it fails on [super dealloc] call on its dealloc method. The de...

Program received signal: “0”

Hi, I am working on page control to show some buttons on each page & to capture the image o it. But, after capturing 10-12 images. I am getting this error -Program received signal: “0” and my application crashed. I know its a memory issue. but i don't know which object is creating problem. Anyone has any solution for this issue. Thank...

How does free() function collect the info about the no. of bytes to be freed.

Possible Duplicate: C programming : How does free know how much to free? free() is called to deallocate the memory allocated by malloc() function call. From where does the free() find the information about the no. of bytes allocated by the malloc() function. I.e., how do you conform the no. of bytes allocated by the malloc() a...

Dynamically loading (AJAX) page content & performance/memory usage

is there any memory of performance issues i need to be aware of when i constantly load/append page content with AJAX like twitter/tumblr i am guessing that as more and more content is loaded (when the user scrolls down), it will clog up the browser cache? is there a need for me to remove the older content (starting of the page). or will...

Why isn't there hardware support for memory management?

Virtual memory is well-supported by modern hardware, but application-level memory allocation is still all implemented software, be it manual heap memory management a-la C and C++, or VM-level garbage collection. Going further than the classic manual memory management vs garbage collection debate, why aren't there hardware-based primitiv...

Concept check: Java's heap-only memory allocation model doesn't mean it has no function call stack, right?

I'm a bit confused on the degree of "absolutes" here. I know that memory allocation in C++ can be done by either heap or stack. And I know that Java's memory allocation can only be done via the heap. Basically, is the following correct? "Java doesn't have stack-based memory allocation [that programmers can directly access]" shouldn'...

Does UINavigationBar retain UINavigationItems pushed onto its stack?

Does UINavigationBar retain nav items pushed onto its stack? In other words, after doing this: _myNavItem = [[UINavigationItem alloc]initWithTitle:@"Home"]; [self.navBar pushNavigationItem:_myNavItem animated:NO]; do I need to release _myNavItem with: [_myNavItem release]; in order to avoid a memory leak? Also, how do I find o...

Obj-C Memory Management Setter Method

I am new to objective-c and ive downloaded the code from here http://apress.com/resource/bookfile/4175 and ran the Chapter 10, 10.01 CarPartsInit xcode project file. One thing i am not clear about is that, does the memory management of a setter method - (void) setEngine: (Engine *) newEngine { [newEngine retain] [engine releas...

C# StreamWriter and StreamReader memory managment problem, why won't memory used deallocate?

So I'm using a StreamReader that uses a MemoryStream to write to a StreamWriter and inside of this application but the memory usage increases by 300mb (From one of the larger inputs) and does not deallocate after Im done using it: StreamWriter log = new StreamWriter("tempFile.txt"); log.Write(reader.ReadToEnd()); log.Close(); reader.Di...

growing python process memory over time

My python code process memory increases dynamically as it stores dynamic data in list, dictionary and tuples wherever necessary. Though all those dynamic data is cleared physically in their variables after then, the memory is not shooting down. Hence i felt like there is a memory leak and i used gc.collect() method to collect all the u...

Memory Warning Level Indicator - iPhone SDK

Hello everyone, I am using a ton of timers that update images in my game, and whenever I run it, the debugger somehow gives me a memory warning indicator level. I try adding some timers through a background thread, but that made a very small difference. Is there anyway I can reduce the memory usage of my app without having to get rid of...

C++ dynamic review tools

What's the best tool (commercial/open source) you've used for dynamic review/memory analysis of a C++ application? EDIT: removed 'static' as there is already a great question on this topic (thanks Iulian!) ...