yet another serious memory problem

hi, it tried some garbage collector workaround and i tried reading memory with Ti.Plaform.availableMemory that results in Cannot read property "availableMemory" from undefined. now i am a little bit disappointed. there will be no solution for the memory consumption in near future?

i have no idea how to solve the vm budget exeed-problem.

using 1.7.2

4 Answers

  • Without seeing your code, I can't offer any specific comments. I'll make the general (and probably unwelcome) comment that you probably need to refactor your code.

    • Create a modular design with content factories imported using commonJS require(). See for more info
    • You can force garbage collection on objects by setting them to null
    • Optimize images and make sure to remove unneeded images from memory (set their proxy objects to null). Remember that JPG images are decompressed in memory so that "small" file could still have an enormous memory footprint.
    • Don't use webviews unless you need their specific functionality. They are one of the most "expensive" components. Don't nest webviews inside tableviews for example.
    • Don't instantiate objects till you need them. This defers, though doesn't eliminate memory requirements
    • Don't store blob objects in your database then select * from table unless you really need those blobs. Better is to store blobs on the file system and file paths in the db.

    Regardless of device memory, your mobile app is allocated only 24 MB of memory.

    — answered 4 years ago by Tim Poulsen
    • Hi Tim, would you say that require() is better than Ti.include() in memory terms or in any other manner? This is a doubt I always had.

      — commented 4 years ago by Javier Rayon
    • require() is better than include(). With include(), all variables are injected into the global namespace, which can cause conflicts. With require(), you get a separate execution context in which local variables & functions are evaluated. Only the items you assign to the exports variable are returned to the calling context, at which point all the rest are released. So require() might not be any faster, but it should reduce memory usage.

      — commented 4 years ago by Tim Poulsen
    • "Remember that JPG images are decompressed in memory so that "small" file could still have an enormous memory footprint."
      Is there a way to release images? or if I remove an image view will it clean up the image decoder?

      — commented 4 years ago by Francis Cleary
    • Francis, you need to delete the imageview (set it to null) to mark it for garbage collection and free its memory. Hiding it, or removing it from the view hierarchy is not enough.

      — commented 4 years ago by Tim Poulsen
    • I can't seem to find any docs on require().. Can you provide a link?

      — commented 4 years ago by Chris Whittle
    • Start by looking at this blog and video.

      — commented 4 years ago by Doug Handy
  • Is the question here why you cannot get the availableMemory value?

    First, in the message you called it Ti.Plaform.availableMemory, where the letter t is missing from Platform. If this was a cut and paste from your source, that would end up making it undefined.

    If that was just a typo in the question and the source was fine, then try forcing a full rebuild by cleaning the project. If this was the first time you reference the Platform class, it may not have picked up on the need to include the Platform class module.

  • i have a very modular design using a factory pattern. that is very nice for working.
    in general i build 6 window at startup since creating them on click feels very slow on android. bad idea, tim?

    — answered 4 years ago by dev 1605
    1 Comment
    • Android is unfortunately slower, something we're working on for future releases. The flip side of what you're doing is that if you build all the windows at startup, then load time will be slower on Android. I guess you have to decide whether your users will be more upset over slow load time or lag when opening a new window.

      — commented 4 years ago by Tim Poulsen
  • Using DDMS i found that Memory allocated to application is get increases as i am navigating screen by screen and after some time it crash application with force close message/Fail to load resources. Even i have remove all objects from window and after that assign null to it. i.e
    Please help Me OUT.