Ivan Porto Carrero
2010-Jan-08 14:23 UTC
[Ironruby-core] Adding a finalizer to a ruby object
Hi
How do I add a finalizer to a ruby object?
I''ve tried using ObjectSpace and define_finalizer.
But the proc never got executed when I called ObjectSpace.garbage_collect
Calling System::GC.collect had the same outcome
and implementing a Finalize method doesn''t seem to have any effect
either
class MyClass
def Finalize
puts "in Finalize"
end
def finalize
puts "in lower finalize"
end
end
MyClass.new
System::GC.collect System::GC.max_generation,
System::GCCollectionMode.forced
#ObjectSpace.garbage_collect
Thanks
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Google Wave: portocarrero.ivan at googlewave.com
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20100108/9dc798ea/attachment.html>
Garbage collection in Ruby is kind of tricky.
Ivan Porto carrero wrote:> Hi > > How do I add a finalizer to a ruby object? > > I''ve tried using ObjectSpace and define_finalizer. > But the proc never got executed when I called > ObjectSpace.garbage_collect > Calling System::GC.collect had the same outcome > > and implementing a Finalize method doesn''t seem to have any effect > either > > class MyClass > > def Finalize > puts "in Finalize" > end > > def finalize > puts "in lower finalize" > end > > endWhat about using a proc, or block and running finalize after yield or proc.call? -Sam -- Posted via http://www.ruby-forum.com/.
Ivan Porto Carrero
2010-Jan-11 07:59 UTC
[Ironruby-core] Adding a finalizer to a ruby object
I specifically wanted to find a counterpart for this C#
public class SomeClass {
private object _unmanagedResource;
public SomeClass(object unmanagedResource){
_unmanagedResource = unmanagedResource;
}
~SomeClass(){
_unmanagedResource.Cleanup();
_unmanagedResource = null;
}
}
I was writing about the dispose pattern and wanted to include a full
counterpart implementation with a finalizer for unmanaged resources.
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
On Mon, Jan 11, 2010 at 6:12 AM, Sam Clopton <lists at ruby-forum.com>
wrote:
> Ivan Porto carrero wrote:
> > Hi
> >
> > How do I add a finalizer to a ruby object?
> >
> > I''ve tried using ObjectSpace and define_finalizer.
> > But the proc never got executed when I called
> > ObjectSpace.garbage_collect
> > Calling System::GC.collect had the same outcome
> >
> > and implementing a Finalize method doesn''t seem to have any
effect
> > either
> >
> > class MyClass
> >
> > def Finalize
> > puts "in Finalize"
> > end
> >
> > def finalize
> > puts "in lower finalize"
> > end
> >
> > end
>
>
> What about using a proc, or block and running finalize after yield or
> proc.call?
>
> -Sam
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20100111/0c6c35b3/attachment.html>
Ivan, I''m not sure but I''ve asked the rest of the team and
someone will get back to you shortly.
~Jimmy
On Jan 11, 2010, at 12:00 AM, "Ivan Porto Carrero" <ivan at
flanders.co.nz<mailto:ivan at flanders.co.nz>> wrote:
I specifically wanted to find a counterpart for this C#
public class SomeClass {
private object _unmanagedResource;
public SomeClass(object unmanagedResource){
_unmanagedResource = unmanagedResource;
}
~SomeClass(){
_unmanagedResource.Cleanup();
_unmanagedResource = null;
}
}
I was writing about the dispose pattern and wanted to include a full counterpart
implementation with a finalizer for unmanaged resources.
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: <http://flanders.co.nz> http://flanders.co.nz
Twitter: <http://twitter.com/casualjim> http://twitter.com/casualjim
Author of IronRuby in Action
(<http://manning.com/carrero>http://manning.com/carrero)
On Mon, Jan 11, 2010 at 6:12 AM, Sam Clopton <<mailto:lists at
ruby-forum.com>lists at ruby-forum.com<mailto:lists at
ruby-forum.com>> wrote:
Ivan Porto carrero wrote:> Hi
>
> How do I add a finalizer to a ruby object?
>
> I''ve tried using ObjectSpace and define_finalizer.
> But the proc never got executed when I called
> ObjectSpace.garbage_collect
> Calling System::GC.collect had the same outcome
>
> and implementing a Finalize method doesn''t seem to have any effect
> either
>
> class MyClass
>
> def Finalize
> puts "in Finalize"
> end
>
> def finalize
> puts "in lower finalize"
> end
>
> end
What about using a proc, or block and running finalize after yield or
proc.call?
-Sam
--
Posted via <http://www.ruby-forum.com/> http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
<mailto:Ironruby-core at rubyforge.org>Ironruby-core at
rubyforge.org<mailto:Ironruby-core at rubyforge.org>
<http://rubyforge.org/mailman/listinfo/ironruby-core>http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20100111/72b7b769/attachment-0001.html>
Ivan Porto Carrero
2010-Jan-11 09:13 UTC
[Ironruby-core] Adding a finalizer to a ruby object
oh if that is the case can they also get back to me with overriding an indexer (http://ironruby.codeplex.com/WorkItem/View.aspx?WorkItemId=3392)? I think that would result in a complete chapter with regards to CLR interop. Thanks a lot :D --- Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero Blog: http://flanders.co.nz Twitter: http://twitter.com/casualjim Author of IronRuby in Action (http://manning.com/carrero) On Mon, Jan 11, 2010 at 9:44 AM, Jimmy Schementi < Jimmy.Schementi at microsoft.com> wrote:> Ivan, I''m not sure but I''ve asked the rest of the team and someone will get > back to you shortly. > > ~Jimmy > > On Jan 11, 2010, at 12:00 AM, "Ivan Porto Carrero" <ivan at flanders.co.nz> > wrote: > > I specifically wanted to find a counterpart for this C# > > public class SomeClass { > > private object _unmanagedResource; > > public SomeClass(object unmanagedResource){ > _unmanagedResource = unmanagedResource; > } > > ~SomeClass(){ > _unmanagedResource.Cleanup(); > _unmanagedResource = null; > } > } > > I was writing about the dispose pattern and wanted to include a full > counterpart implementation with a finalizer for unmanaged resources. > > --- > Met vriendelijke groeten - Best regards - Salutations > Ivan Porto Carrero > Blog: <http://flanders.co.nz>http://flanders.co.nz > Twitter: <http://twitter.com/casualjim>http://twitter.com/casualjim > Author of IronRuby in Action ( <http://manning.com/carrero> > http://manning.com/carrero) > > > > On Mon, Jan 11, 2010 at 6:12 AM, Sam Clopton < <lists at ruby-forum.com> > lists at ruby-forum.com> wrote: > >> Ivan Porto carrero wrote: >> > Hi >> > >> > How do I add a finalizer to a ruby object? >> > >> > I''ve tried using ObjectSpace and define_finalizer. >> > But the proc never got executed when I called >> > ObjectSpace.garbage_collect >> > Calling System::GC.collect had the same outcome >> > >> > and implementing a Finalize method doesn''t seem to have any effect >> > either >> > >> > class MyClass >> > >> > def Finalize >> > puts "in Finalize" >> > end >> > >> > def finalize >> > puts "in lower finalize" >> > end >> > >> > end >> >> >> What about using a proc, or block and running finalize after yield or >> proc.call? >> >> -Sam >> -- >> Posted via <http://www.ruby-forum.com/>http://www.ruby-forum.com/. >> _______________________________________________ >> Ironruby-core mailing list >> <Ironruby-core at rubyforge.org>Ironruby-core at rubyforge.org >> <http://rubyforge.org/mailman/listinfo/ironruby-core> >> http://rubyforge.org/mailman/listinfo/ironruby-core >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core at rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100111/eb64206e/attachment.html>
We don?t support finalizers yet, but it shouldn?t be too much work to make
ObjectSpace#define_finalizer work with Ruby objects. We might also consider
providing some means to override CLR Finalize method.
Tomas
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at
rubyforge.org] On Behalf Of Jimmy Schementi
Sent: Monday, January 11, 2010 12:45 AM
To: <ironruby-core at rubyforge.org>
Subject: Re: [Ironruby-core] Adding a finalizer to a ruby object
Ivan, I''m not sure but I''ve asked the rest of the team and
someone will get back to you shortly.
~Jimmy
On Jan 11, 2010, at 12:00 AM, "Ivan Porto Carrero" <ivan at
flanders.co.nz<mailto:ivan at flanders.co.nz>> wrote:
I specifically wanted to find a counterpart for this C#
public class SomeClass {
private object _unmanagedResource;
public SomeClass(object unmanagedResource){
_unmanagedResource = unmanagedResource;
}
~SomeClass(){
_unmanagedResource.Cleanup();
_unmanagedResource = null;
}
}
I was writing about the dispose pattern and wanted to include a full counterpart
implementation with a finalizer for unmanaged resources.
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
On Mon, Jan 11, 2010 at 6:12 AM, Sam Clopton <lists at
ruby-forum.com<mailto:lists at ruby-forum.com>> wrote:
Ivan Porto carrero wrote:> Hi
>
> How do I add a finalizer to a ruby object?
>
> I''ve tried using ObjectSpace and define_finalizer.
> But the proc never got executed when I called
> ObjectSpace.garbage_collect
> Calling System::GC.collect had the same outcome
>
> and implementing a Finalize method doesn''t seem to have any effect
> either
>
> class MyClass
>
> def Finalize
> puts "in Finalize"
> end
>
> def finalize
> puts "in lower finalize"
> end
>
> end
What about using a proc, or block and running finalize after yield or
proc.call?
-Sam
--
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org<mailto:Ironruby-core at rubyforge.org>
http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/ironruby-core/attachments/20100111/c005e101/attachment.html>