אנסה להבהיר ע"י דוגמה, מצ"ב קוד
private void rotateArr(int[] array, boolean direction, int move) { int[] tempArr = null; int tempSize = 0; if (move > array.length / 2) { direction = !direction; tempSize = array.length-move; }else if (direction) // Shift all elements left by one tempSize = array.length - move; else // Shift all elements right by one tempSize = move; //else; tempArr = new int[tempSize]; System.arraycopy(array, 0, tempArr, 0, tempSize); System.arraycopy(array, tempSize, array, 0, array.length - tempSize); System.arraycopy(tempArr, 0, array, array.length - tempSize, tempSize); }
יש לי בעיה של שחרור זכרון מהקטע הזה, לדעתי משום שאני משנה את הפרמטר בתוך אגב, בדקתי במקרים אחרים ולמשל אם אני מציב NULL לתוך משתנה שהועבר כפרמטר לפונקציה , זה לא משפיע עליו אחרי החזרה ואילו כאן - כן משפיע גם אחרי סיום הפונקציה. למה?