Results 1 to 2 of 2
  1. #1
    Asolpdrag is offline Member
    Join Date
    Feb 2012
    Rep Power

    Default Reducing memory usage for an object

    I am making a Path Finding program in java and I have an object called Cell. Then with a method I generate a grid which is a 2-dimension array of objects Cell.

    The object cell has two variables, int xCoord and int yCoord but my main PathFind class needd the objects to have two more variables int xParent and int yParent. But not every Cell needs to have the for variables, so I want to add those variables to the Cell object once it has been created.

    Any ideas?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Rep Power

    Default Re: Reducing memory usage for an object

    There are many ways to implement this, but given the title of the thread - are you running into memory that would necessitate the worry? That question raised, a few ways would be to extend Cell and have the variables in the child class, or if you prefer to favor composition over inheritance create a 'wrapper' class for Cell which contains the values.

Similar Threads

  1. Checking memory usage
    By jsobel in forum Advanced Java
    Replies: 4
    Last Post: 06-15-2012, 05:34 PM
  2. Application Memory Usage...
    By switch in forum AWT / Swing
    Replies: 1
    Last Post: 01-26-2012, 07:13 PM
  3. Lowering Memory usage
    By CuddlyKittens11 in forum Advanced Java
    Replies: 6
    Last Post: 04-27-2011, 07:53 PM
  4. Memory usage
    By Moon_E in forum New To Java
    Replies: 20
    Last Post: 07-09-2010, 10:53 PM
  5. JVM memory usage
    By lardum in forum New To Java
    Replies: 7
    Last Post: 06-26-2008, 03:30 AM

Posting Permissions

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