Rakhi, 1. its ca is array of contacts. So it will consume more space.10 contact objects will be created & stored in array ca. 2.ca is single object so it will consume less space. Inside loop you are creating 10 contact objects but only 1 contact object will retain reference. All other contact objects are eligible for garbage collection
SCJP <br />SCWCD <br />SCBCD <br />SCEA-1
Joined: May 01, 2008
You mean that in first case 10 active references to 10 objects will be there in the memory heap. but in 2nd case only 1 will be active at a time but then what about the other 9 contacts in the 2nd case will they be stored anywhere and can we access them any how?
Joined: Jan 22, 2008
Originally posted by rakhee gupta: In 2nd case only 1 will be active at a time but then what about the other 9 contacts in the 2nd case will they be stored anywhere and can we access them any how?
NOW you cant access them once you have lost reference to those 9 objects. You should have stored that reference inside the method somewhere , so that you can again access them
Why are you worrying about 10 object references' difference? The two bits of code are totally different in that one creates and retains 10 Contacts and that the other loses 9 of them. If you need 10 Contacts you need 10 Contacts. You are probably sitting in front of enough silicon to hold 1000000 Contacts easily.