# Malloc error with String#\<\< / String#+

**URL:** <https://www.ruby-forum.com/t/malloc-error-with-string-string/161392>\
**Category:** Ruby\
**Created:** [February 26, 2009, 5:18am UTC](https://www.ruby-forum.com/t/malloc-error-with-string-string/161392 "2009-02-26T05:18:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tjholowaychuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@tjholowaychuk](https://www.ruby-forum.com/u/tjholowaychuk)\
**Post date:** [February 26, 2009, 5:18am UTC](https://www.ruby-forum.com/t/malloc-error-with-string-string/161392/1 "2009-02-26T05:18:09Z")

</div>

The repo is here if anyone wants to take a look  
[http://github.com/visionmedia/dm-forms/tree/master](http://github.com/visionmedia/dm-forms/tree/master)

This is the first time I have had a memory error of any kind, heres the  
output message:

forms ruby(7152,0xa041efa0) malloc: \*\*\* mmap(size=1073741824) failed  
(error code=12)  
\*\*\* error: can’t allocate region  
\*\*\* set a breakpoint in malloc\_error\_break to debug  
ruby(7152,0xa041efa0) malloc: \*\*\* mmap(size=1073741824) failed (error  
code=12)  
\*\*\* error: can’t allocate region  
\*\*\* set a breakpoint in malloc\_error\_break to debug  
./examples/…/lib/dm-forms/base.rb:21:in `<<': failed to allocate memory (NoMemoryError) from ./examples/../lib/dm-forms/base.rb:21:in `form’  
from ./examples/…/lib/dm-forms/helpers.rb:19:in `form’  
from examples/benchmarks.rb:11  
…

I did a ruby-prof test on that same file and got

%self total self wait child calls name  
79.15 4.50 4.50 0.00 0.00 174 String#+  
13.24 0.75 0.75 0.00 0.00 84 String#\<\<  
2.23 5.41 0.13 0.00 5.29 21  
DataMapper::Form::Helpers#form

Looks REALLY odd to me … when running more than 10-ish times it seems  
to cause this memory error so something is really wrong that I have  
done. Any suggestions? if you run ‘rake benchmark’ you will (probably)  
see what i mean, I have tried without benchmarking as well this still  
occurs so something stupid is going on.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![tjholowaychuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@tjholowaychuk](https://www.ruby-forum.com/u/tjholowaychuk)\
**Post date:** [February 26, 2009, 2:26pm UTC](https://www.ruby-forum.com/t/malloc-error-with-string-string/161392/2 "2009-02-26T14:26:58Z")

</div>

Ruby version? (ruby -v)  
Operating system and version? (uname -a)  
Source of Ruby package? (e.g. from distribution X, or compiled yourself)

---

<div class="post-metadata">

**Author:** ![tjholowaychuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@tjholowaychuk](https://www.ruby-forum.com/u/tjholowaychuk)\
**Post date:** [February 26, 2009, 5:10pm UTC](https://www.ruby-forum.com/t/malloc-error-with-string-string/161392/3 "2009-02-26T17:10:34Z")

</div>

Brian C. wrote:

> Ruby version? (ruby -v)  
> Operating system and version? (uname -a)  
> Source of Ruby package? (e.g. from distribution X, or compiled yourself)

right sorry, heres all that:

ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]

Darwin Macintosh.local 9.5.0 Darwin Kernel Version 9.5.0: Wed Sep 3  
11:29:43 PDT 2008; root:xnu-1228.7.58~1/RELEASE\_I386 i386

Its just 1.8.6 which was installed on the mac already

---

<div class="post-metadata">

**Author:** ![tjholowaychuk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/82dd89/32.png) [@tjholowaychuk](https://www.ruby-forum.com/u/tjholowaychuk)\
**Post date:** [February 26, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/malloc-error-with-string-string/161392/4 "2009-02-26T20:59:07Z")

</div>

OK, I’m not a Mac expert I’m afraid.

ulimit -a

would be the first thing I’d try, to see what process memory and stack  
limits have been set, if any.

\*\*\* mmap(size=1073741824) failed (error code=12)

looks like something is asking to allocate exactly 1GB of RAM, which  
seems fishy to me. Maybe it’s been growing this space and has now hit  
1GB.

If your Ruby process really is chewing up this much RAM (monitor it  
using ‘top’ while it runs), you’ll need to find out why.

- building a data structure which is too big?

- holding onto references longer than you need?

- however there are some strange failure modes very occasionally (esp.  
with threads or continuations) where a phantom object reference remains  
in the stack area scanned by the GC, but is not really live. There have  
been some patches posted a while back which you could try.
