Results 1 to 8 of 8
  1. #1
    mr_empty is offline Member
    Join Date
    Mar 2008
    Posts
    15
    Rep Power
    0

    Default image processing memory problem

    hi all,
    now i 'm creating image manupulating program and facing memory issue. this is one of the command in my program:

    WritableRaster parent = dst.getWritableTile(tx, ty);

    where dst is tiledimage class object, and i loop this command so the memory usage is acumulately consumed. i need to free the parent object. but there is no associate dispose() method, and i run System.gc() and that's no help.
    so now the point is , how do i free the memory of the parent object consumed?

    Thanks!

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Give us the code around this call. I suspect your problem is in there.
    Preferably the whole method (at least the whole loop).

  3. #3
    mr_empty is offline Member
    Join Date
    Mar 2008
    Posts
    15
    Rep Power
    0

    Default

    <code>

    for(int ty = 0; ty < ny; ty++) {


    for(int tx = 0; tx < nx; tx++) {
    WritableRaster parent = dst.getWritableTile(tx, ty);
    bounds = parent.getBounds();
    int startBand = 0;



    System.out.println("src length"+src.length);
    for(int i = 0; i < src.length; i++) {
    int[] bandList = new int[bands[i]];
    int k = startBand;
    for(int j = 0; j < bands[i]; j++ ) {
    bandList[j] = k++;
    System.out.println(bandList[j]);
    }
    startBand += bands[i];
    WritableRaster child =
    parent.createWritableChild(bounds.x, bounds.y,
    bounds.width, bounds.height,
    bounds.x, bounds.y,
    bandList);
    //new int[i+1]);



    src[i]=JAI.create("fileload", fileNames[i]);
    child.setRect(src[i].getData(bounds));
    child=null;
    src[i].dispose;
    child=null;
    System.gc();



    }
    dst.releaseWritableTile(tx, ty);

    parent=null;

    System.gc();


    }
    }

    </code>

    actually i want to free the memory of parent, child and src. and after i call system.gc i found it 's a bit rise in memory usage rather than freeing of memory, so now i wonder how to get the command work...

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    The code tags use square brackets.

    Why have you declared bounds outside the loops? There doesn't seem to be any need for that.

    Anyway, as for the memory thing, calling gc() really isn't a fix. Neither is setting stuff to null. It is far better to ensure everything is in the correct scope. That is the smallest scope possible. But it looks to me (apart from bounds, which isn't exactly a memory hog) that you have done that. You could try moving the code in the second loop into its own method, which can help ensure stuff goes out of scope. Pass in the tx and ty for the tile.

    What's using the memory? Have you profiled this? Looked at a heap dump maybe? This code as it stands (though I could be missing something) seems to be OK. Which I would say means you'll need to look at the memory (ie profiling, and heap analysis).

  5. #5
    mr_empty is offline Member
    Join Date
    Mar 2008
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    The code tags use square brackets.

    Why have you declared bounds outside the loops? There doesn't seem to be any need for that.

    Anyway, as for the memory thing, calling gc() really isn't a fix. Neither is setting stuff to null. It is far better to ensure everything is in the correct scope. That is the smallest scope possible. But it looks to me (apart from bounds, which isn't exactly a memory hog) that you have done that. You could try moving the code in the second loop into its own method, which can help ensure stuff goes out of scope. Pass in the tx and ty for the tile.

    What's using the memory? Have you profiled this? Looked at a heap dump maybe? This code as it stands (though I could be missing something) seems to be OK. Which I would say means you'll need to look at the memory (ie profiling, and heap analysis).

    actually, is the parent object memory allocated in heap? how do i free its memory since it does not have dispose method...

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    In Java, put simply, do not worry about memory allocation and deallocation. That's what the garbage collector does...and you do not control that. gc() does nothing more than suggest the garbage collector do a full collection at some point, if it isn't too much bother. It really isn't something you should have to call.

    parent is declared inside the second for-loop. Each time that loop goes back round the object that parent is referencing is eligible for collection, so long as there are no other references to it.

    I have no idea if getWritableTile is creating a new object each time, in fact.

    You really need to take a heap dump and see what's using the memory.

  7. #7
    mr_empty is offline Member
    Join Date
    Mar 2008
    Posts
    15
    Rep Power
    0

    Default

    Quote Originally Posted by Tolls View Post
    In Java, put simply, do not worry about memory allocation and deallocation. That's what the garbage collector does...and you do not control that. gc() does nothing more than suggest the garbage collector do a full collection at some point, if it isn't too much bother. It really isn't something you should have to call.

    parent is declared inside the second for-loop. Each time that loop goes back round the object that parent is referencing is eligible for collection, so long as there are no other references to it.

    I have no idea if getWritableTile is creating a new object each time, in fact.

    You really need to take a heap dump and see what's using the memory.
    thanks for reply, so the point is, i cannot free the memory of the parent and child object, actually i cannot free any memory , so how can i take the heap dump?

    actually i 've run the program in debug mode and see that parent and child object did occupy the certain memory, just dun know how to free them...
    Last edited by mr_empty; 12-16-2009 at 03:27 AM.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default

    Google is your friend.

    So that'll give you the heap dump, and then use the Eclipse analyser to see what the possible leak culprits are. That is assuming it's a leak and not simply a case of the JVM not having enough memory allocated.

    As for freeing memory, as I say, you do not control that. The collector will do it for you. I have no idea what your code is supposed to be doing, so I cannot say what is correct or not about it.

Similar Threads

  1. still problem with image processing
    By syarizma in forum Advanced Java
    Replies: 2
    Last Post: 01-26-2012, 07:47 PM
  2. Image processing
    By syarizma in forum Advanced Java
    Replies: 6
    Last Post: 08-17-2009, 06:15 AM
  3. Processing an Image with csimage
    By coldfire in forum New To Java
    Replies: 2
    Last Post: 01-27-2009, 09:21 AM
  4. Image Processing
    By Josh_FL in forum Advanced Java
    Replies: 4
    Last Post: 12-30-2008, 03:45 AM
  5. image processing
    By sathish natrajan in forum Java 2D
    Replies: 2
    Last Post: 11-06-2008, 06:13 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •