J
John Baro
Going back a week or so I posted a question about whether it was better to
declare an object within a for loop so it gets declared each time or out of
the loop and then reuse the object each time.
Basic consensus was that it was better to declare it outside if it was going
to take a while to initialise.
Anyway..
More thoughts
If we declare it within the loop then each time it will create a new object
on the heap as compared to declaring it outside and setting it to new each
time which would theoretically reuse the object already on the heap.
Eventually to my thinking this will degrade performance as the GC will be
forced into action to clean up the heap.
On second thougths I dont think this is correct.
If we set any object to new it will create a new object on the heap
regardless of where the object was declared?
If we are setting an object to an existing object then it will simply point
to that object on the heap regardless of where it was declared?
Any thoughts??
Cheers
JB
Life is not a reality TV show.
declare an object within a for loop so it gets declared each time or out of
the loop and then reuse the object each time.
Basic consensus was that it was better to declare it outside if it was going
to take a while to initialise.
Anyway..
More thoughts
If we declare it within the loop then each time it will create a new object
on the heap as compared to declaring it outside and setting it to new each
time which would theoretically reuse the object already on the heap.
Eventually to my thinking this will degrade performance as the GC will be
forced into action to clean up the heap.
On second thougths I dont think this is correct.
If we set any object to new it will create a new object on the heap
regardless of where the object was declared?
If we are setting an object to an existing object then it will simply point
to that object on the heap regardless of where it was declared?
Any thoughts??
Cheers
JB
Life is not a reality TV show.