Won't WIN32OLE_EVENT.new leak?

Won’t WIN32OLE_EVENT.new leak? A WIN32OLE object will sooner or later
be freed (right?), when garbage collection kicks in. But a
WIN32OLE_EVENT object will never be freed, as it is kept in a global
array and is never removed from that array.

nikolai

Hello,
In message “Won’t WIN32OLE_EVENT.new leak?”
on 07/08/16, “[email protected][email protected]
writes:

Won’t WIN32OLE_EVENT.new leak? A WIN32OLE object will sooner or later
be freed (right?), when garbage collection kicks in. But a
WIN32OLE_EVENT object will never be freed, as it is kept in a global
array and is never removed from that array.

WIN32OLE_EVENT object is freed when ruby process terminated.
And while ruby process running WIN32OLE_EVENT object is not freed.

Because WIN32OLE_EVENT object should not be freed until
WIN32OLE object is freed.
If WIN32OLE_EVENT object is freed before WIN32OLE object is freed,
then ruby is segmentation fault.
To avoid this segmentation fault, WIN32OLE_EVENT object is added
in a global array and should not be freed.
I think this solution is not so good, but I have not found
the best (or better) solution.

Regards,
Masaki S.

Hello,
In message “Re: Won’t WIN32OLE_EVENT.new leak?”
on 07/08/20, “[email protected][email protected]
writes:

Can’t the WIN32OLE_EVENT object be linked to the WIN32OLE object so
that when the WIN32OLE object is freed, we make sure WIN32OLE_EVENT is
freed as well?

Thank you. It seems to me that your suggestion is good solution.
I’d like to study this solution.
(I need some time to study.)

Regards,
Masaki S.

On Aug 17, 3:35 pm, Masaki S. [email protected] wrote:

And while ruby process running WIN32OLE_EVENT object is not freed.

Because WIN32OLE_EVENT object should not be freed until
WIN32OLE object is freed.

Can’t the WIN32OLE_EVENT object be linked to the WIN32OLE object so
that when the WIN32OLE object is freed, we make sure WIN32OLE_EVENT is
freed as well?

nikolai

Hello,

In message “Re: Won’t WIN32OLE_EVENT.new leak?”
on 07/08/20, “[email protected][email protected]
writes:

which would have been easier if Windows supported fork(), but I guess
one can’t get everything one wants…

I noticed that backword compatibility would be lost if
WIN32OLE_EVENT object is freed when WIN32OLE object is freed.

For example, the following script would not work.

def ie_start
ie = WIN32OLE.new(‘InternetExplorer.Application’)
ie.visible = true
ev = WIN32OLE_EVENT.new(ie, ‘DWebBrowserEvents’)
ev.on_event(“Quit”) {|*args| $LOOP = false}
ev.on_event(“BeforeNavigate”) {|*args| puts args[0]}
ie = nil
GC.start
end
$LOOP = true
while $LOOP
WIN32OLE_EVENT.message_loop
end

In current Win32OLE, even if ie would be freed by GC.start,
ev is not freed. And InternetExplorer keep running.
You can control InternetExplorer interactively.
While you would keep navigating any web page,
ev keep recieving the events from InternetExplorer.

As your suggestion, if ev would be freed when ie is freed,
then there is no way to recieve the events
from InternetExplorer.

So I could find the way how to free ev
when InternetExplorer process is terminated,
but I have not found it.

Regards,
Masaki S.

On Aug 20, 1:02 pm, Masaki S. [email protected] wrote:

And while ruby process running WIN32OLE_EVENT object is not freed.
(I need some time to study.)
OK. I’ll see if I can come up with a patch as well. I solved the
problem for my project by doing everything in a separate process,
which would have been easier if Windows supported fork(), but I guess
one can’t get everything one wants…

nikolai