×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Manually GC call !

    Hi All,

    I am getting null pointer exception due to heap memory low in Nokia 3110c and 6300.
    If I call the System.gc() manually then the null pointer exception is over but the application is running too slow.
    I am first checking 500kb of available heap memory if not there then calling the gc manually.

    Is there any other way to increase the heap memory?If yes then how?

    Please suggest me what to do in this scenario...



    Thanks & Regards,
    Ajit

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: Manually GC call !

    Quote Originally Posted by ajitkumar26 View Post
    Hi All,
    Is there any other way to increase the heap memory?If yes then how?
    Thanks & Regards,
    Ajit
    Well there is no magic code, tool to increase the device heap memory. However you can write/optimize your code in such a m manner that it consumes the as least memory as possible.

    What your app is doing?
    are you getting OOM?
    How are you rendering, updating and key processing doing in your code?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Manually GC call !

    Quote Originally Posted by raj_J2ME View Post
    Well there is no magic code, tool to increase the device heap memory. However you can write/optimize your code in such a m manner that it consumes the as least memory as possible.

    What your app is doing?
    are you getting OOM?
    How are you rendering, updating and key processing doing in your code?
    In my application I am displaying a list of name on the screen.
    If the length of the name is greater than the screen width the I am scrolling the text.
    To scroll the name I am doing by using the timer.And I am using the canvas.So each time I am repainting the screen.So it consumes more heap memory.Thats why I am checking the heap memory for 500kb and then manually calling the gc.

    After calling Gc my application is running too slowly.
    Even I am not sure the cause of becoming slow?
    Is is for calling the GC manually?


    Thanks & Regards,
    Ajit

  4. #4
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Manually GC call !

    You should note that on a good modern VM it generally makes little sense call System.gc(). It generally never makes sense to set attributes to null unless that is the only way you're making them unreachable.

    1.Setting attributes to null rarely makes sense. Design your software properly, so that references go out of scope when you're no longer using them.
    2.Calling System.gc() rarely makes sense. Let the JVM do the work for you -- that's why we use a VM instead of managing our own memory.
    3.Yes, let the VM manage your memory, it will GC when it needs to. However, if you've got poorly designed software, it can defeat the GC in the VM. In this case, track down your memory leaks and refactor the software (easier said than done, though).

    Well, what is the time that you might be sleeping your run()?
    I guess you are reading the data in a infinite loop, is it so?
    Make sure that the data reading code executes just once or when required...

    are you doing the scrolling in the same or different thread?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  5. #5
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Manually GC call !

    Quote Originally Posted by raj_J2ME View Post
    You should note that on a good modern VM it generally makes little sense call System.gc(). It generally never makes sense to set attributes to null unless that is the only way you're making them unreachable.

    1.Setting attributes to null rarely makes sense. Design your software properly, so that references go out of scope when you're no longer using them.
    2.Calling System.gc() rarely makes sense. Let the JVM do the work for you -- that's why we use a VM instead of managing our own memory.
    3.Yes, let the VM manage your memory, it will GC when it needs to. However, if you've got poorly designed software, it can defeat the GC in the VM. In this case, track down your memory leaks and refactor the software (easier said than done, though).

    Well, what is the time that you might be sleeping your run()?
    I guess you are reading the data in a infinite loop, is it so?
    Make sure that the data reading code executes just once or when required...

    are you doing the scrolling in the same or different thread?
    I am scrolling on the same thread.
    when the control is on a particular text then the scrolling of the text will start untill the control is on another text.
    What to do please suggest me...

    Thanks & Regards,
    Ajit

  6. #6
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Manually GC call !

    Well, what is the time that you might be sleeping your run()?
    I guess you are reading the data in a infinite loop, is it so?
    Make sure that the data reading code executes just once or when required...
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  7. #7
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Manually GC call !

    Quote Originally Posted by raj_J2ME View Post
    Well, what is the time that you might be sleeping your run()?
    I guess you are reading the data in a infinite loop, is it so?
    Make sure that the data reading code executes just once or when required...
    timer.schedule(timerTask, 750, 300);
    calling for the scrolling the text.
    I am not getting you?
    Can you please explain the below text

    the data reading code executes just once or when required...


    Thanks & Regards,
    Ajit

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Manually GC call !

    Why are you scheduling/starting the timer after the 750 mills.
    Just try this tm.schedule(tt, 0, 100);
    I am sure that the application speed will increase.

    the data reading code executes just once or when required...
    Means that when you are reading the contacts is that code is inside the loop?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  9. #9
    Registered User
    Join Date
    Nov 2009
    Posts
    188

    Re: Manually GC call !

    Quote Originally Posted by raj_J2ME View Post
    Why are you scheduling/starting the timer after the 750 mills.
    Just try this tm.schedule(tt, 0, 100);
    I am sure that the application speed will increase.


    Means that when you are reading the contacts is that code is inside the loop?
    By implementing tm.schedule(tt, 0, 100);
    the speed of the scrolling text is increasing but not the application excecution speed.
    If I am running the application on the Netbeans inbuilt emulators its working fine.
    The speed is also very high.
    And the heap memory is also 2mb.
    But in the device it is too slow.
    What to do... Please help...



    Thanks & Regards,
    Ajit

  10. #10
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: Manually GC call !

    I would suggest you that test the same application on the some other device too either of the same family or of some other.
    Another suggestion would be try to implement the Runnable and check whether using the Thread the speed of the application can be speeded up.

    Kindly share the main run() of the Timer implementation.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  11. #11
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Manually GC call !

    Quote Originally Posted by raj_J2ME View Post
    Calling System.gc() rarely makes sense.
    He's right. The VM will call gc() for you before an OutOfMemoryError can be thrown, so calling gc() yourself is generally a waste of time. On some devices (especially Series 60s), calling gc() will slow your application down significantly. This is because the VM automatically performs "mini" gc's, and only performs a "full" gc if the mini gc doesn't free up enough memory. A call to gc() always performs a "full" collection, which takes much longer than a "mini".

    Only reasons to call gc():

    1. You have just created a lot of garbage, and you have a "busy" screen displayed, and you want to get the clean-up done now while the user is expecting a pause. For example, when moving from one level to another in a game.

    2. You're developing for a very old device that lacks a defragmenting garbage collector (for example, MIDP-1.0 Series 40, or Motorola V300/V400/V500). Carefully placed gc() calls can help reduce fragmentation. Best called after a large number of objects have been released (become unreachable). Again, moving from one level to the next in a game is a good example.

    Graham.

  12. #12
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: Manually GC call !

    On many Java implementations calling System.gc() will cause the system to flush SoftReferences, effectively flushing all the caches in the JVM. (Of course, an OutOfMemoryError also flushes SoftReferences, so that may be at work here.)

    In most desktop/mainframe Java implementations System.gc()is so rarely used correctly and so commonly used incorrectly that the JVMs ignore it by default.

Similar Threads

  1. incoming call auto answer problem
    By manmay.gupta in forum Symbian
    Replies: 12
    Last Post: 2010-04-07, 10:24
  2. Replies: 5
    Last Post: 2009-08-26, 09:36
  3. Playing video on call
    By bhaskarmallu in forum Streaming and Video
    Replies: 0
    Last Post: 2008-11-10, 10:07
  4. Replies: 4
    Last Post: 2008-09-10, 10:13
  5. Can not trap Outgoing call disconnection
    By jugnoyasir in forum Symbian
    Replies: 1
    Last Post: 2005-08-13, 10:50

Posting Permissions

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