Possible Duplicate:
Is Java “pass-by-reference”?
if we have big byte[]
array (like 40Mb) and we want to send it in method
method(array);
will the array be copied? So memory will increase by another 40Mb in Java env => 80Mb, right?
If yes, how can we destroy the 'first' array after calling the method?
No, the array will not be copied.
In Java, everything is always passed by value.
Variables of non-primitive types are references to objects. An array is an object, and a variable of an array type is a reference to that array object.
When you call a method that takes a non-primitive type parameter, the reference is passed by value - that means, the reference itself is copied, but not the object it refers to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With