# Trouble with embedded Ruby Interpreter for Windows Application

**URL:** <https://rubytalk.org/t/trouble-with-embedded-ruby-interpreter-for-windows-application/397>\
**Category:** ruby-talk\
**Created:** [26 June 2002 12:57 UTC](https://rubytalk.org/t/trouble-with-embedded-ruby-interpreter-for-windows-application/397 "2002-06-26T12:57:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Weil\_Stefan\_S-RD-AS5](https://avatars.discourse-cdn.com/v4/letter/w/439d5e/32.png) [@Weil\_Stefan\_S-RD-AS5](https://rubytalk.org/u/Weil_Stefan_S-RD-AS5)\
**Post date:** [26 June 2002 12:57 UTC](https://rubytalk.org/t/trouble-with-embedded-ruby-interpreter-for-windows-application/397/1 "2002-06-26T12:57:02Z")

</div>

Hello,

maybe a Ruby guru can give a solution to my problem?  
I started using Ruby this month (but I read all  
information I could find) and do not know how to solve  
the problem without changing the Ruby source code.

My goal is to enrich a Windows GUI application by an embedded  
ruby interpreter. The Ruby dll should be loaded at runtime,  
because the application must not depend on the availability  
of a certain ruby version. The user can choose which Ruby dll  
he/she wants to use, and even switch from one version to another.

At first, I noticed that there is a ruby\_init() which among  
other things saves the stack base address for later usage  
by ruby’s garbage collection. So it was not possible to call  
the Ruby interpreter’s rb\_eval\_string() from a different  
stack context, for example from different threads. Doing so  
would raise fatal runtime errors as my experiments soon showed.  
I might disable garbage collection permanently, but obviously  
this is not a good solution.

It is not possible to restart the ruby interpreter with a clean  
state without restarting the whole Windows application. This is  
caused by the fact that ruby\_init() only saves the stack base  
address at the first call, so a restart (which uses a different  
stack context in our application) leads to desaster.

If it were possible to unload the Ruby dll completely, this  
would solve my problem because then I could load it again and  
ruby\_init() calculates a new stack base. But this works only  
for very simple Ruby scripts. A script which uses require()  
loads additional shared libraries (dlls) which are never released.  
The Ruby dll won’t unload with FreeLibrary() after a successful  
require() statement.

So what can I do???

Thanks for your comments.

Stefan

---

<div class="post-metadata">

**Author:** ![ts1](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@ts1](https://rubytalk.org/u/ts1)\
**Post date:** [26 June 2002 13:17 UTC](https://rubytalk.org/t/trouble-with-embedded-ruby-interpreter-for-windows-application/397/2 "2002-06-26T13:17:24Z")

</div>

> for very simple Ruby scripts. A script which uses require()  
> loads additional shared libraries (dlls) which are never released.  
> The Ruby dll won't unload with FreeLibrary() after a successful  
> require() statement.

Have you tried to call FreeLibrary() with the values contained in  
ruby\_dln\_librefs ?

Guy Decoux
