You need to sign in to do that
Don't have an account?

Object creation
Hi everyone,
I created a reference variable a.
and instantiated it .
how i thought what happens during instantiation is,
First instantiation->
Account1 got its heap area
Reference Variable 'a' point to 'Account1' memory location
Second instantiation->
Account2 got its heap area
reference variable 'a' now repoint to 'Account2'
Account 1 is ready for garbage collection.
But when i run below code.heap size remains same for second instantiation.how can this be true?where am i going wrong?
account a;
System.debug('Current Heap:::' + Limits.getHeapSize());
a = new account(name ='Account1');
System.debug('Current Heap:::' + Limits.getHeapSize());
system.debug(a);
a = new account(name = 'Account2');
System.debug('Current Heap:::' + Limits.getHeapSize());
system.debug(a);
Could you please explain why you're concerned with this? This isn't usually an area that developers need to worry about on our platform. Are you running into trouble with somehting or is this merely an academic exercise?
BTW, this is an older blog posting but it might help: http://blogs.developerforce.com/developer-relations/2012/05/passing-parameters-by-reference-and-by-value-in-apex.html
Hi Ryan,thanks for the links.its very clearly explained for pass by reference/pass by value.
But applying those concepts as well,
i cannot figure out why heap size is not getting increased in my code above
as it should be.any idea?