# Require 'tk' causes segfault later

**URL:** <https://rubytalk.org/t/require-tk-causes-segfault-later/3313>\
**Category:** ruby-talk\
**Created:** [4 December 2002 20:11 UTC](https://rubytalk.org/t/require-tk-causes-segfault-later/3313 "2002-12-04T20:11:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ptkwt1](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@Ptkwt1](https://rubytalk.org/u/Ptkwt1)\
**Post date:** [4 December 2002 20:11 UTC](https://rubytalk.org/t/require-tk-causes-segfault-later/3313/1 "2002-12-04T20:11:21Z")

</div>

I’ve got a Ruby app that creates a tree data structure and then  
recursively walks that structure to generate some data - that’s the short  
description (the longer description has to do with generating test  
vectors for finite state machines (FSMs)). It’s been working fine.  
Yesterday I decided that I wanted to be able to see what that tree structure  
looks like so I decided to use SvgCanvas (see SvgCanvas in the RubyGarden  
wiki) which uses dot to generate an svg file and imports it into TkCanvas -  
it works pretty nicely, BTW (except for the segfault on large testcases).

After making these additions, it seemed to work fine. But then I tried a  
larger testcase (which used to work) that generates a tree with several  
hundred nodes and I found that the script segfaults. I turned off the  
tree drawing feature thinking that that was the problem, but it still  
segfaulted which was odd (as far as I knew the script was back to the  
state it was in prior to adding the drawing feature). Then I noticed that  
I still had the ‘require “tk”’ at the top of the script. After commenting  
that out the problem went away.

Does requiring Tk take a lot of memory or something? Any ideas?

(BTW: TkCanvas is pretty nice as it’s quite easy to get postscript from a  
canvas)

Phil

> **···**
>
> –  
> "Or perhaps the truth is less interesting than the facts?"  
> Amy Weiss (accusing [theregister.co.uk](http://theregister.co.uk) of engaging in ‘tabloid journalism’)  
> Senior VP, Communications  
> Recording Industry Association of America

---

<div class="post-metadata">

**Author:** ![Robert\_McGovern2](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@Robert\_McGovern2](https://rubytalk.org/u/Robert_McGovern2)\
**Post date:** [5 December 2002 10:50 UTC](https://rubytalk.org/t/require-tk-causes-segfault-later/3313/2 "2002-12-05T10:50:55Z")

</div>

Phil Tomson wrote:

> hundred nodes and I found that the script segfaults. I turned off the  
> tree drawing feature thinking that that was the problem, but it still  
> segfaulted which was odd (as far as I knew the script was back to the  
> state it was in prior to adding the drawing feature). Then I noticed that  
> I still had the ‘require “tk”’ at the top of the script. After commenting  
> that out the problem went away.
> 
> Does requiring Tk take a lot of memory or something? Any ideas?

Which version of Ruby are you using and on which platform?

Rob

---

<div class="post-metadata">

**Author:** ![Ptkwt1](https://avatars.discourse-cdn.com/v4/letter/p/85e7bf/32.png) [@Ptkwt1](https://rubytalk.org/u/Ptkwt1)\
**Post date:** [5 December 2002 20:55 UTC](https://rubytalk.org/t/require-tk-causes-segfault-later/3313/3 "2002-12-05T20:55:33Z")

</div>

In article [3DEF2FE9.6050404@spellmanhv.co.uk](mailto:3DEF2FE9.6050404@spellmanhv.co.uk),

> Phil Tomson wrote:
> 
> > hundred nodes and I found that the script segfaults. I turned off the  
> > tree drawing feature thinking that that was the problem, but it still  
> > segfaulted which was odd (as far as I knew the script was back to the  
> > state it was in prior to adding the drawing feature). Then I noticed that  
> > I still had the ‘require “tk”’ at the top of the script. After commenting  
> > that out the problem went away.
> > 
> > Does requiring Tk take a lot of memory or something? Any ideas?
> 
> Which version of Ruby are you using and on which platform?

ruby 1.6.7 (2002-03-01) [i686-linux-gnu]

I also tried with 1.7.3 on linux and it also segfaulted.

It’s not a huge problem for me right now as I’ve changed the code so that  
the require is done after the large tree structure is built and that works  
fine - it’s just that anytime there’s a segfault it could be an indicator  
that something is rotten somewhere 😉 in this case I’m not sure if it’s  
in the tk extension or Ruby itself.

One thing to note: The tree structure is built recursively and in this  
particular test case the recursion goes pretty deep - could it be some  
kind of stack overflow problem?

Phil

> **···**
>
> ## Robert McGovern [robertm@spellmanhv.co.uk](mailto:robertm@spellmanhv.co.uk) wrote:
> 
> “Or perhaps the truth is less interesting than the facts?”  
> Amy Weiss (accusing [theregister.co.uk](http://theregister.co.uk) of engaging in ‘tabloid journalism’)  
> Senior VP, Communications  
> Recording Industry Association of America
