From: Chuck Remes Date: 2011-07-31T01:25:08+09:00 Subject: Re: avoiding capturing local variables in closures On Jul 30, 2011, at 3:14 AM, Robert Dober wrote: > > > 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. I want to be clear that I understand you. Here's some code that I think illustrates what you mean. class A def some_callback(bigarg1, bigarg2) foo = transform(bigarg1) bar = transformagain(bigarg2) @another_instance = B.new avoid_capture(foo, bar) end def avoid_capture(foo, bar) # self (from an instance of A) is captured in the block that # is now held by @another_instance @another_instance.schedule_for_execution { baz(foo, bar) } end end Right? cr