From: 7stud -- Date: 2011-07-31T16:27:40+09:00 Subject: Re: avoiding capturing local variables in closures Robert Dober wrote in post #1013853: > > > Answered by Michael > >> Further, what if I have an instance var that is referencing some large data? Do > I need to worry >about that being captured by the block or does it not > matter > because the block has already >captured self? > > At first sight you need to worry if you pass the block to a method > outside of the receiver because that will create a new reference to > "self". > As long as you pass the block around in the same object I do not see an > issue. > Huh? class Dog attr_accessor :val def initialize(x) @greeting = x end def make_proc return Proc.new { greet } end def greet puts @greeting end end d = Dog.new('lots of memory') p = d.make_proc d = nil p.call --output:-- lots of memory -- Posted via http://www.ruby-forum.com/.