For example,
if method returns huge amount of data like:
Data[] data = getData(); //will return 100Mb. Java memory usage increased by 100
if we call getData without assigment to data, will java will use this 100Mb anyway?
getData(); //returns huge data but we don't assign it to var. Memory usage wasn't increased
Yes.
Data[]data is simply a reference to the data. So it will use the 100MB.However if you don’t assigned the returned data to any variable and it don’t have any other references, the data will be quickly garbage collected and memory freed.