byte data = new byte[len];
Take space in heap or in LAM?
The pointer to the array object (data) will be allocated either on the variable stack (if declared in a method block) or in the class data (if declared as a member variable). The actual array itself (byte[len]) will be allocated on the heap.
What does LAM stand for?
LAM stands for Large Array Memory
So if the data will allocated on the heap,
I can check if there are free space for allocate a data of "len" size.
int freeMem = Runtime.getRuntime().freeMemory();
if (freeMem > len) new byte[len]
else "There isn't sufficent free memory"
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2015, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.