java - How to free memory in 2-D array -
i have long code. logic follows: have 2-d array in java. so, have values inside locations: [0][0], [0][1], [0][2] , values in:[1][0], [1][1], [1][2]. @ point, made comparisons, , done first row. want free memory of: [0][0], [0][1], [0][2] , move next locations [2][0], [2][1], [2][2].
how can this. can not overwrite [0][0], [0][1], [0][2],my code programmed move next row [2][0], [2][1], [2][2] faced memory constraints , want free memory first row [0][0], [0][1], [0][2] not need more. need current row , previous make comparison. so, want delete first row whenever finish comparison.
update: tried assign null unused array locations following:
for (int f = 0; f <= capacity; f++) { table[f][i-2] = (integer) null; } my array of type int , need last 2 columns. first 1 not needed once move 1 more position forward. when applied above code assign null, got:
java.lang.nullpointerexception
set null each reference in row
for (int = 0; < arr.length; i++) { arr[0][i] = null; } arr should array of references, not primal types
edit
primal types (e.g. int) can use wrapper-class (e.g. java.lang.integer instead of int : integer[][] instead of int[][])
edit2
equivalent previous loop is:
arr[0] = new integer[arr.length]; array new integer[arr.length] contains null values
Comments
Post a Comment