yet another serious memory problem

You must Login before you can answer or comment on any questions.

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

— asked 3 years ago by dev 1605
0 Comments

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 http://wiki.appcelerator.org/display/guides/Building+Reusable+Factories 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 3 years ago by Tim Poulsen
answer permalink
6 Comments
  • 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 3 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 3 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 3 years ago by Francis Cleary

  • Show 3 more comments

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 3 years ago by dev 1605
answer permalink
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 3 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 window.remove(viewname); viewname=null; window.close(); window=null. Please help Me OUT.

Your Answer

Think you can help? Login to answer this question!