www.digitalmars.com         C & C++   DMDScript  

DMDScript - Walter : 2 questions about your JavaScript engine

reply adzheng <adzheng_member pathlink.com> writes:
I've been using your JS engine for a while and have couple questions. Can you
please give me some hints?

1. I've a C++ object derived from Dobject exposed to JS. When the program ends,
I've tried to use mem.fullcollect() and the object seems to be deleted but the
destructor doesn't get called. Therefore a memory leak occors if I need to free
some momory in the destructor.

2. I've loaded JS engine in thread A and tried to call a JS function from thread
B it seems like the engine doesn't like it since the thread context is
different. Is there a way to switch JS calling thread context then make the call
across thread successfully?

Thanks in advance,
adzheng
Nov 04 2005
parent "Walter Bright" <newshound digitalmars.com> writes:
"adzheng" <adzheng_member pathlink.com> wrote in message
news:dkgro6$3g5$1 digitaldaemon.com...
 I've been using your JS engine for a while and have couple questions. Can

 please give me some hints?

 1. I've a C++ object derived from Dobject exposed to JS. When the program

 I've tried to use mem.fullcollect() and the object seems to be deleted but

 destructor doesn't get called. Therefore a memory leak occors if I need to

 some momory in the destructor.

You can use GC::setFinalizer to run some custom code when the object is free'd by the GC.
 2. I've loaded JS engine in thread A and tried to call a JS function from

 B it seems like the engine doesn't like it since the thread context is
 different. Is there a way to switch JS calling thread context then make

 across thread successfully?

The engine is designed around the 'apartment thread' model, where the engine thread contexts are all distinct from each other. Be careful crossing thread boundaries, as the GC instances don't scan or know about each other.
Nov 05 2005