Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ausername

macrumors newbie
Original poster
Feb 28, 2009
25
0
I made an application that uses a lot of loops, and deals with MB's of text at a time. After the program has been running for about 10 seconds, it goes to "not responding." After about 2 minutes, I get this error:

aTestApp(1550) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
aTestApp(1550) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
aTestApp(1550) malloc: *** mmap(size=2097152) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

The application has garbage collection on... I am also manually releasing everything myself. Is there an easy way around this error? Or what?

Any help or info would be great, thanks. :)

I am using Mac OS X 10.5.6,
Xcode 3.1.2,
The application is being compiled in 32 bit universal, I tried 32/64 universal.
 
It sounds like you are simply running out of memory so malloc is failing. Try running your app in Instruments to observe its allocation behaviors. You may not be freeing memory early enough or at all.
 
I tried using instruments

The allocation is spiked at the top, I am reference counting every object, and like I said before, garbage collection is on. Also, I don't understand why it goes to "Not responding," when there is still 2GB of memory left.

The program reads in about 1MB of text from a file, does some things with it, and releases it, and then repeats. The memory should not fill up like this, and even if I was not releasing anything, everything is automatically an auto-release object.
 
If you have GC enabled, those autorelease and release methods don't do anything.

You could try calling [[NSGarbageCollector defaultCollector] collectIfNeeded] (or collectExhaustively)
 
I am very confused. You are malloc'ing, but then saying things are autoreleased. I don't really think it goes both ways. If you allocate some memory using malloc, the only way you're getting it back is free. For objects that are autoreleased, they won't go away until a pool gets drained/released. Maybe you should set up autorelease pools around areas of the code where a lot of objects are being created so they can be released sooner?

Showing us code would definitely make this easier.

-Lee

EDIT: Not as familiar with GC, so look into kainjow's suggestion. The autorelease pool stuff sounds like it doesn't apply.
 
Sorry, I thought this was malloc failing, but it's actually mmap.

How are you reading in your files? If you're mapping in all your files, you might not be properly unmapping them, so you eventually fill up the address space.

If you're using mmap directly, then the fact that the app is GC is probably irrelevant. However, if you're reading them in with NSData's memory mapping option, or something like that, then kainjow's suggestion might help, if the NSDatas (or whatever) aren't being finalized to unmap the files. (Although, isn't the collector be running in another thread? Unless the loop is really tight and files are being mapped in very rapidly, the collector should still be able to collect the garbage NSDatas.)
 
You should probably show some code. It looks like you're leaking something.
 
Garbage collection doesn't help if you don't do it right. Garbage collection will not throw anything that can still be reached. Pointers to objects that are not used anymore need to be set to NULL, otherwise they can't be collected.
 
truly an error

I am running R on my new 8 GB Mac Book Pro and also getting this error -- I suppose it is an R problem the allocation of greater memory -->

Best,
Anne

Details: Running on publicly available GEO data set GSE2118 --> and I get this error
Error: cannot allocate vector of size 594.9 Mb
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

It has a dim of about 12,000 rows by 12 columns... and its trying to allocate memory that exceeds what it can do... but I think it is a quirky R problem
 
I am running R on my new 8 GB Mac Book Pro and also getting this error -- I suppose it is an R problem the allocation of greater memory -->

Best,
Anne

Details: Running on publicly available GEO data set GSE2118 --> and I get this error
Error: cannot allocate vector of size 594.9 Mb
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug
R(2046,0xa07ee720) malloc: *** mmap(size=623751168) failed (error code=12)
*** error: can't allocate region
*** set a breakpoint in malloc_error_break to debug

It has a dim of about 12,000 rows by 12 columns... and its trying to allocate memory that exceeds what it can do... but I think it is a quirky R problem

Is that 2.5GB of memory, or am I reading it wrong.

6237511688*4 bytes ~= 2.5GB. ??
 
Is that 2.5GB of memory, or am I reading it wrong.

6237511688*4 bytes ~= 2.5GB. ??

I think the number reported by mmap is already in bytes. Half a gig is quite a chunk, but on an 8GB Pro (a 64bit machine) this should really not be a problem... Perhaps your VM got badly fragmented, and/or perhaps R is 32 bit only..?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.