# RMagick: UnableToConcatenateString \`

**URL:** <https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712>\
**Category:** Ruby\
**Created:** [September 4, 2007, 8:42am UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712 "2007-09-04T08:42:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 8:42am UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/1 "2007-09-04T08:42:56Z")

</div>

I have a program to generate my website bluebottleimages.org

It creates thumbnails using Rmagick. I run the program (on the server),  
and it goes for a while, but then I get

RMagick: UnableToConcatenateString `  
'.  
Warning: recursive semaphore lock detected!

and it’s stopped there.

It has come up invariably at the same spot, so I thought it was  
corrupted image files, but even after replacing them I get the error  
message. Now I’m thinking that it’s probably just that I’m over-using  
server resources making all those thumbnails… Do you think that’s  
the case, or is it more likely that there’s a problem with my program?

If you like I can post my code.

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 1:21pm UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/2 "2007-09-04T13:21:48Z")

</div>

Jonathan D. wrote:

> and it’s stopped there.
> 
> It has come up invariably at the same spot, so I thought it was  
> corrupted image files, but even after replacing them I get the error  
> message. Now I’m thinking that it’s probably just that I’m over-using  
> server resources making all those thumbnails… Do you think that’s  
> the case, or is it more likely that there’s a problem with my program?
> 
> If you like I can post my code.

Try adding a periodic call to GC.start to your program. See this note:  
[http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 7:25pm UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/3 "2007-09-04T19:25:33Z")

</div>

Tim H. wrote:

> Try adding a periodic call to GC.start to your program. See this note:  
> [http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)

Thanks! It works perfectly now

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 7:39pm UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/4 "2007-09-04T19:39:14Z")

</div>

Tim H. wrote:

> used by individual image objects with the Magick::Image#destroy! method,  
> thus eliminating the need to call GC.start from time to time.

Seems like ruby could help out libraries like RMagick by exposing an API  
to tell GC that memory has been allocated by something other than ruby’s  
malloc. Did anyone ever pursue that?

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 7:30pm UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/5 "2007-09-04T19:30:38Z")

</div>

Jonathan D. wrote:

> Tim H. wrote:
> 
> > Try adding a periodic call to GC.start to your program. See this note:  
> > [http://rubyforge.org/forum/forum.php?thread\_id=1374&forum\_id=1618](http://rubyforge.org/forum/forum.php?thread_id=1374&forum_id=1618)
> 
> Thanks! It works perfectly now

Good news!

Looking forward, starting with RMagick 2.0.0 you can free the memory  
used by individual image objects with the Magick::Image#destroy! method,  
thus eliminating the need to call GC.start from time to time.

---

<div class="post-metadata">

**Author:** ![jonathan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/aeb1de/32.png) [@jonathan](https://www.ruby-forum.com/u/jonathan)\
**Post date:** [September 4, 2007, 9:37pm UTC](https://www.ruby-forum.com/t/rmagick-unabletoconcatenatestring/113712/6 "2007-09-04T21:37:56Z")

</div>

Joel VanderWerf wrote:

> Tim H. wrote:
> 
> > used by individual image objects with the Magick::Image#destroy! method,  
> > thus eliminating the need to call GC.start from time to time.
> 
> Seems like ruby could help out libraries like RMagick by exposing an API  
> to tell GC that memory has been allocated by something other than ruby’s  
> malloc. Did anyone ever pursue that?

This may help in the general case but for RMagick not so much. RMagick  
doesn’t know how much memory ImageMagick is allocating for an image.  
Even if it knew or could compute the amount of the initial allocation  
the amount of memory used for an image can vary over the lifetime of the  
image. I suppose RMagick could give Ruby an estimate, which might help  
some.

I gave some thought to trying to get ImageMagick to use Ruby’s memory  
management API. It seems like it might solve the problem, but I’m not  
sure that the IM developers would want to devote that much effort to  
Ruby users.

Adding #destroy! is something I could do on my own. It more-or-less  
parallels the way you can close files and sockets and otherwise free up  
resources that Ruby either doesn’t know about or might let hang around  
longer than necessary.
