Hi,

JIT Compiler is allowed to discard the null assisgnment because there are 2
consecutives writes into the same location, so only the last one can be
kept without changing the meaning of the program.
>From the GC point of view as soon as the reference is no longer pointing to
the allocate object, it is considered as dead, and may be reclaimed in the
next cycle.
But depending on if data is a field or local variable will determine if GC
can reclaim it sooner.
In the case of a local variable as soon as the variable is no more read, a
GC can already collect the byte[] before assigning local variable to null
(with the help of liveness analysis).
For the field case, the byte[] will reclaimable once the assignment is
done, so maybe after the allocation of the second byte[]

Regards

On Tue, Nov 13, 2018 at 6:28 PM Shevek <[email protected]> wrote:

> Given the following code:
>
> byte[] data = ...;
>
> {
>     data = null;
>     data = new byte[N];
> }
>
> Is the compiler allowed to discard the assignment of null, because it's
> "dead" in language terms? My argument is that it isn't dead because it
> allows the garbage collector to respond to pressure within the 'new' and
> reuse the space, but in language terms, this presumably isn't defined,
> and it would seem to be legal for the first assignment to be removed.
>
> Thank you.
>
> S.
>
> --
> You received this message because you are subscribed to the Google Groups
> "mechanical-sympathy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to