• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why did Tawny choose Bob’s method over Kent’s, when Kent’s used less memory?  RSS feed

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in head first it compared two code segments where one was the right answer...cant find the answer

Bob, show me how you handled updating the list of contact
objects.” Bob quickly drew a code fragment on the board:



“Tawny I know we’re tight on memory, but your spec said that we had to be able to access
individual contact information for all ten allowable contacts, this was the best scheme I could
cook up”, said Bob. Kent was next, already imagining coconut cocktails with Tawny, “Bob,”
he said, “your solution’s a bit kludgy don’t you think?” Kent smirked, “Take a look at this
baby”:




“I saved a bunch of reference variables worth of memory, Bob-o-rino, so put away your
sunscreen”, mocked Kent. “Not so fast Kent!”, said Tawny, “you’ve saved a little memory, but
Bob’s coming with me.”.

Why did Tawny choose Bob’s method over Kent’s, when Kent’s used less memory?

is it because the first solution makes more reference name variables...where the second one made only one?

 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry...i see it explains the answer a few pages down...sorry again
 
Paul Clements
Ranch Hand
Posts: 99
1
Chrome Eclipse IDE MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the second piece of code the same Object Ref variable is being used on each iteration. When the loop finishes refc will reference only one object i.e. the last one created. The others will have been orphaned off when you re-used refc. At that point they would have become eligible for garbage collection. An array is the correct solution i.e. Bob is the man!
 
jon ninpoja
Ranch Hand
Posts: 291
3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes saw that Paul...the nice thing is that I realised this before i read the solution...boy was i happy!!!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!