[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Won't WIN32OLE_EVENT.new leak?

nikolai.weibull@gmail.com

8/16/2007 12:36:00 PM

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

5 Answers

Masaki Suketa

8/17/2007 1:36:00 PM

0

Hello,
In message "Won't WIN32OLE_EVENT.new leak?"
on 07/08/16, "nikolai.weibull@gmail.com" <nikolai.weibull@gmail.com> 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 Suketa




nikolai.weibull@gmail.com

8/20/2007 7:09:00 AM

0

On Aug 17, 3:35 pm, Masaki Suketa <masaki.suk...@nifty.ne.jp> wrote:
> Hello,
> In message "Won't WIN32OLE_EVENT.new leak?"
> on 07/08/16, "nikolai.weib...@gmail.com" <nikolai.weib...@gmail.com> 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.

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

Masaki Suketa

8/20/2007 11:02:00 AM

0

Hello,
In message "Re: Won't WIN32OLE_EVENT.new leak?"
on 07/08/20, "nikolai.weibull@gmail.com" <nikolai.weibull@gmail.com> 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.
>
> 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 Suketa


nikolai.weibull@gmail.com

8/20/2007 2:30:00 PM

0

On Aug 20, 1:02 pm, Masaki Suketa <masaki.suk...@nifty.ne.jp> wrote:
> Hello,
> In message "Re: Won't WIN32OLE_EVENT.new leak?"
> on 07/08/20, "nikolai.weib...@gmail.com" <nikolai.weib...@gmail.com> 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.
>
> > 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.)

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

Masaki Suketa

8/24/2007 12:23:00 PM

0

Hello,

In message "Re: Won't WIN32OLE_EVENT.new leak?"
on 07/08/20, "nikolai.weibull@gmail.com" <nikolai.weibull@gmail.com> 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.)
>
> 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...

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 Suketa