Arne VajhHj <arne@vajhoej.dk> wrote:
t1 = cost of allocating one foobar
t2 = cost of GC one short lived foobar
t3 = cost of GC one longlived foobar
t4 = cost of initializing a foobar (constructor or otherwise)
I think, the point is, that t4(new object) != t4(re-init)
Why ?
If they do the same work they should take the same time.
Oh, the argument is correct, but not the premise ... :-)
I would not assume so - it is bad practice doing lot of work in
constructors.
I spoke of "initialisation", and humpty-dumpty as I am, this
is not limited to the constructor, but includes all that is
necessary to make the Object "usable". :-)
I think it is obvious, that it will very much depend on the object,
whether the transition to that "initialized"-state is easier reachable
from "all zeroed out"-state or from "fields have arbitrary values from
their previous use"-state (which may again mean, that some fields may
not need to be changed at all).
As an extreme example, I claim that if my object was e.g. wrapping
a byte[1000] then looping and setting each element to zero is likely
taking more effort, than just dropping it and allocating a new one.
Could very well be.
of the one.