function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Newbie10Newbie10 

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);

ryanjuptonryanjupton

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?

Newbie10Newbie10
Its a self study exercise for DEV 501, to understand how it works behind the scene
Newbie10Newbie10

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?