From: lalawawa Date: 2010-01-19T01:20:10+09:00 Subject: Re: basic question: passing a modifiable argument to a routine On Jan 18, 10:47 am, Rick DeNatale wrote: > On Mon, Jan 18, 2010 at 9:25 AM, lalawawa wrote: > > When you say that += creates a different object, then are you saying > > that when I do > > > a = 0 > > while a < 1000000 > >  a += 1 > > end > > > it creates a million different objects and garbage collects most of > > them?  Isn't that horribly inefficient for just doing integer > > arithmetic? > > In this case, those integers are all Fixnums which are represented by > immediate values, so no allocation or GC is involved. > > Of course if you are really concerned about efficiency you can always > do that calculation as: > > a = (1000000*1000000 + 1000000) / 2 > > -- > Rick DeNatale > > Blog:http://talklikeaduck.denhaven2.com/ > Twitter:http://twitter.com/RickDeNatale > WWR:http://www.workingwithrails.com/person/9021-rick-denatale > LinkedIn:http://www.linkedin.com/in/rickdenatale Well, I'm trying to understand. If I do a = 0 while a < 1_000_000 a += 1 end a.object_id at the end is 2000001. Does this mean a 2 million instances of fixnum are in existance, just not garbage collected?