I'm creating a video editing program with QTKit.
There is a sample program provided by apple here,
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/QTKitApplicationTutorial/CreatingaQTKitStoporStillMotionApplication/CreatingaQTKitStoporStillMotionApplication.html
My test program is based on this program, but use
QTMovie *movie = [[[QTMovie alloc] initToWritableFile:#"foo.mov" error:nil] autorelease];
and
[movie updateMovieFile];
for saving memories.
If there are not so many frames, the program runs well. But with so many frames, the program begins to show
QTKitServer(5618,0xa0924540) malloc: *** mmap(size=33554432) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
I checked memory leaks with Instruments,
but Live Bytes are not so big and found no memory leaks.
Overall Bytes is really big but is this a reason of this problem?
Any ideas will be appreciated.
Thanks,
The overall bytes should not be a problem unless there is an unreported memory leak.
After some googling some people seem to get this problem when compiling for 32bit, what architecture are you compiling against?
Related
Now i'm developing iPhone app but it seems happen memory leak. I found by Instruments:
I have question:
-- how to find where is code that happen memory leak about "Malloc xx bytes"?
-- I think I can't improve memory leak in Library. Example for "Foundation", "StoreKit" and so on, right?
Switch to the call tree view to find the areas of your code allocating the leaked memory. For more detailed information, see my answer to the following question:
Unable to track memory issue
Also for clearer representation of memory leaks select Allocation tool, go to File>Recording Options and tick "Discard events for freed memory".
In this way all the spikes that you will see in the chart will be actual unfreed memory
When I run my app using Instruments, I face the following issues before the app eventually crashes:
Allocations: There is a constant increase in total bytes up to 1-2GB. This increase is seen even before any leak is detected.
Leaks: There are multiple leaks. On looking at the Call tree, I find they are in the system libraries:
with symbol names, malloc_zone_malloc and malloc in libsystem_malloc.dylib
the bytes used column shows 192 Bytes, 100%
When I run it in xcode, I get a 'terminated due to memory pressure' error.
My questions are-
Is filing a bug report with apple the only solution since the leaks are in system libraries?
Are the leaks, the only reason behind the crash; given that only 192 Bytes are leaked and memory usage increases even before leaks?
When troubleshooting memory allocation and leaks it's almost always a good idea to exclude system libraries and look for your code only. It's very unlikely that you have discovered such basic and easy to find bug in core libraries and nobody took care of this before.
The facts that leaks are indicated in malloc doesn't mean anything. All memory allocations will go through mallocs at the end. You need to look for bugs in your code first.
I was reading a really large file into memory on the main thread (not just the simple dataWithContentsOfFile: method, I was also doing some data manipulation), and my app crashed. After I moved this process to a background thread, the app doesn't crash anymore. The only thing that happens is that the NSData I get is nil.
Is it possible that only my background thread is interrupted without affecting the main thread, or am I missing something? Also, can I count on this behaviour and just display an error message when the NSData is nil, without the app to crash? Thank you in advance.
Edit:
The log I get is:
malloc: * mmap(size=629800960) failed (error code=12)
error: can't allocate region
** set a breakpoint in malloc_error_break to debug
The file I was using is about 250 MB large.
I know why it crashed on the main thread. My question is, why didn't it crash on a secondary thread?
I guess it can depend on the crash, but if it is a problem of lack of memory (you can both be using too much memory or be creating too many objects) it will crash the entire app.
You should try to test the app with smaller files and see how it behaves.
i am writing a iPad application and displaying the tableView in my application. I have two options in tableview:
includeAll
ExcludeAll
Once i click the IncludeAll all cells should be selected. I am loading more then 10000 records. once i select the include all i got one error message.
error message is
malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
Googling will reveal quite a few tutorials on using instruments to understand what is going on with your memory:
How to debug memory leaks: (tutorial)
http://www.raywenderlich.com/2696/how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial
And another:
Finding Obj-C memory leaks (video)
http://www.youtube.com/watch?v=R449qEuexNs&feature=related
Probably because your simulator is able to allocate ~500Mb of memory while your iPad is not able to do it. I think you should rethink what you are doing
do you really need so much memory?
isn't it just a calculating bug? (maybe a wrong sizeof or whatever)
in any case this is really too much data to be handled
Our app is experiencing occasional crashes in the field (discovered via BugSense) due to what looks like out of memory or memory corruption conditions, so to help me track them down I enabled the following:
Malloc Scribble
Malloc Guard Edges
Guard Malloc
Objective-C Zombie Objects
Malloc Stack Logging
Log Exceptions.
After interacting with the app for a bit in the Simulator (less than 30 seconds), the following message is displayed:
GuardMalloc[TrafficDemoEmp-2430]: allocate_pages(): virtual memory exhaused!
GuardMalloc[TrafficDemoEmp-2430]: expandUniquingTable(): VMCopyFailed
GuardMalloc[TrafficDemoEmp-2430]: allocate_pages(): virtual memory exhaused!
GuardMalloc[TrafficDemoEmp-2430]: expandUniquingTable(): VMCopyFailed
With Guard Malloc disabled the app works fine but with it enabled the app crashes with these messages. When I profile with the Leaks and Allocations instruments no leaks are found and the Live Bytes value for all memory ranges between 30 MB and 80 MB (depending on what it's doing at the time). Surely that's not too much memory for an app.
However, the messages point to my app using too much memory but I'm not sure what is leading to the virtual memory exhaustion. Are there other tools or debugger settings that are available in Xcode to help?
Thanks,
David
User1118321 was right. NSZombies was the cause of this problem.
Filing this answer so an answer can be accepted.