×

Discussion Board

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

    Smile Runtime.freeMemory() issue on various devices

    Dear Folks,

    All I need your help and suggestions/recommendations..

    What I am doing:
    Well I am doing one project in which there is some criteria that if the free runtime memory,
    m_freeMemory = Runtime.getRuntime().freeMemory();
    is less than 60000 then I am not supposed to make the network call else if the memory is greater than that then only the call to the network will be done..

    What Issue I am facing:
    Even on the good and high end devices like Nokia E72, Nokia E75 and Nokia 6760 slider I am always getting the free memory less or sometime more than what I need.However there are very less occurrence when the free memory is greater than defined one.Hence my project testing is getting delayed.I would like to share that the required memory that device must have must be equal or greater than 60000.This seems very much wondering that these very good devices does not have this much of memory.

    It will be also interesting to know that all the three devices are of the same family that is S60 3rd Edition, Feature Pack 2.

    What I Found:
    While I was testing the same app on Nokia E71, which is S60 3rd Edition, Feature Pack 1 and I found that the app is running very sweet and there are no issues at all about the free memory.

    So guy's I am looking for the suggestion/finding about the above issue, I am sure that you can give some challenging solutions to the above mentioned problem.

    Feel free to ask as many questions as you can have, in order to help me.
    Thanks in advance for any suggestion or even the time to read this issue.

    Looking forward to hear from all of you guy's..
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  2. #2
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Runtime.freeMemory() issue on various devices

    You are doing a garbage collect before calling that right ?
    Also, it might have something to do with the dynamic heap memory size ?
    It might be that on older versions (the E-71) extra memory is being instantiated relatively faster than on the FP2 devices, probably the FP2 are more "optimized", as in they get extra memory assigned right when they are running out of it ?

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

    Re: Runtime.freeMemory() issue on various devices

    Hey Tiger,
    Thanks for the quick reply...
    Quote Originally Posted by Tiger79 View Post
    You are doing a garbage collect before calling that right ?
    Yes

    Quote Originally Posted by Tiger79 View Post
    Also, it might have something to do with the dynamic heap memory size ?
    What do you mean?


    Quote Originally Posted by Tiger79 View Post
    It might be that on older versions (the E-71) extra memory is being instantiated relatively faster than on the FP2 devices
    Well I am not sure about..

    What I am surprised about is that fact -
    Free Memory on Nokia E71 is much larger than the E72/E75/6760 slide..and the real cause of my problem.What are your recommendations?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  4. #4
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Runtime.freeMemory() issue on various devices

    "What do you mean?"

    well what I mean is that the devices mentioned by you are S60's, thus they have a dynamic heap size...
    The available memory (heap-size) for the application changes accroding to the application needs...
    So the underlying OS might assign 1 MB of heap memory to your app, when the OS sees the app will need more (the ceiling of 1 MB has nearly been reached) the OS will dinamically increse the heap size to (for example) 1.5MB or 2MB thus giving your app more headroom regarding available memory...
    This means that a Runtime.getRuntime().freeMemory(); call can result in some unexpected values...
    For example you could keep the same amount of free Memory whilst your used memory is continuesly increasing...
    Or you might expect you're memory to run out, but instead it actually increases whilst your used memory is increasing as well...
    Btw, are you also keeping track of the used memory ?

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

    Re: Runtime.freeMemory() issue on various devices

    Again thanks for the reply Tiger,

    Yeah I am keeping the track of the used memory.
    You know what if I am rendering the free memory,on the canvas and I am not doing anything on the screen/with the app even the memory is getting changed...
    Even all this seems some kind of natural to me, however my matter of worrying is why this free memory is varying with such a huge value on the two devices?
    So what to do next in order to get rid of this?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  6. #6
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Runtime.freeMemory() issue on various devices

    well even if you aren't doing anything the underlying OS might be, it might simply throw in a gc itself...
    and then dinamically change the heap size cause the app is using less memory after the gc...
    I have to admit though, that I actually cannot decipher what the specific problem is from your posts...

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

    Re: Runtime.freeMemory() issue on various devices

    Runtime.freeMemory() isn't much use on Series 60s, because of the expanding heaps. If you want to know if you have a certain amount of memory on Series 60s:

    Code:
    public static boolean canAllocate(int bytes) {
        boolean can;
        try {
            byte[] array = new byte[bytes];
            can = true;
        } catch (OutOfMemoryError oom) {
            can = false;
        }
        return can;
    }
    Assuming there is enough free memory on the device (remember that it is shared with other running applications), Series 60 heaps appear to expand quite happily up to 16Mb. The heap never gets smaller.

    Graham.

  8. #8
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Runtime.freeMemory() issue on various devices

    it never shrinks ?
    how smart, so if an app has a big spike and the heap increases accordingly other apps actually might get out of memory whilst the app causing it actually doesnt need the memory anymore :P

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

    Re: Runtime.freeMemory() issue on various devices

    I think it would just be too complicated to release part of the heap. At the very least, it would require a full defragmentation of the heap, as you'd only (realistically) want to attempt to release the top end of the heap, not create holes in the middle. (The Series 60 JVM uses a generational heap management system, so it doesn't routinely perform full sweeps of the heap.) Peak memory usage is probably less of a problem than you might expect, as the largest things most J2ME apps load will be images, and Series 60 tends to keep those in a separate, shared resource heap.

    The same is true of most C programs... memory acquired from the operating system on a call to malloc() is not released back to the OS on a call to free(). Unless you use operating system specific requests (like HeapAlloc() and HeapFree() to create and discard entire new heaps on Windows), the application's heap always grows, never shrinks. Because C memory allocation tends to suffer badly from fragmentation, a program's heap can grow way beyond the amount that the application ever uses. (And that's before you factor leaks into the equation.)

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

    Re: Runtime.freeMemory() issue on various devices

    Thanks for the reply guy's..

    So what next, what conclusion?
    What I should do and what not?
    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: Runtime.freeMemory() issue on various devices

    On Series 60, I wouldn't worry. You're not likely to run out of memory. If you really want to check, do it by attempting to create a byte[] and catch the OutOfMemoryError. If you want to be extra safe, allocate twice as much as you actually need. But really, you're only looking for 60k, and that's nothing on the devices you're talking about.

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

    Re: Runtime.freeMemory() issue on various devices

    Thanks for the reply dear Graham,
    So if I conclude this discussion as a whole so this will be like this,

    "There are no clear pictures that why this difference in the memory is occurring on the two same series devices just differing the feature pack at all??

    Hence there there is nothing I can do about it,neither I can found the reasons for the same nor can do anything to increase the same.However do not you think that some Expert should answer this post and should explain the reasons for this issue, so that at least I can explain the same to the client that this is happening due to this and that.What you say Graham?

    Another interesting thing about this is that this is happening on the same S60 3rd Edition, Feature Pack 2 devices and not on any other one.I guess there should be some reason for this.
    SO I really request specially to the Forum Nokia Experts that please share the reasons for this.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  13. #13
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Runtime.freeMemory() issue on various devices

    Surely there is a reason : the OS is actually a different Feature Pack...
    That means that the OS (different version again) might simply handle the dynamic heap memory differently than the older SP1...
    It;s like asking :
    why is my firewall better on Windows XP SP2 than on the standard Windows XP ?
    Is it only the SP2 ? Well, the answer is simple : yes They added/tweaked/changed/optimized funtionality, I guess that's what they did in S60 3rd 2FP as well...
    Or maybe another Java Runtime version ?

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

    Re: Runtime.freeMemory() issue on various devices

    Sure.

    What freeMemory() reports at any given time is down to a number of factors.

    * The device's memory management strategy. For devices with expanding heaps, this will include parameters like the initial size of the heap, and the size by which the heap grows when it becomes full.

    * How many objects you're using.

    * How many objects system classes are using.

    * How many classes are loaded (which will be affected by the platform's class loading strategy).

    * How much garbage is lying around (system classes create garbage as well as your code).

    * What information the device stores in the Java heap, and what information it stores elsewhere (such as images in special resource/video/large-object heaps).

    * How big objects of different classes are.

    Most of these factors are outside of your control. They are device-dependent, and can vary from one operating system to another; or one version to another; or even one firmware release to another.

    Really, freeMemory() is almost useless, unless you know the exact platform you're running on, and details of how that platform manages memory.

    Graham.

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

    Re: Runtime.freeMemory() issue on various devices

    Thanks guy's for replying..

    Well you are correct and I am surely agree with you.Let me tell this all stuff to the client and let me have some feedback from, and if I will be having some issue then I will share with you.

    Thanks for the time and wonderful help and support.
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Search for BT devices
    By girish3110 in forum Mobile Java General
    Replies: 1
    Last Post: 2009-04-11, 07:11
  2. Which FP1/FP" devices does Music Player Remote Control API not work on
    By kevinvernon in forum Symbian Media (Closed)
    Replies: 0
    Last Post: 2009-02-09, 12:17
  3. Replies: 7
    Last Post: 2007-09-05, 10:38
  4. BluetoothPMPExample discovers devices randomly
    By mrautane in forum Symbian Networking & Messaging (Closed)
    Replies: 3
    Last Post: 2007-02-17, 06:39
  5. Different Symbian Devices, different SDK's???
    By Difflam in forum Symbian Tools & SDKs
    Replies: 3
    Last Post: 2003-04-08, 10:46

Posting Permissions

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