Experion Presentation at JavaOne 2011: Memory optimizing Java ME applications


Published on

The session "Memory-Optimizing Java ME Applications" was taken by Sreekumar Pillai, CTO, Experion Technologies at the 2011 JavaOne conference held in San Francisco, California.

Enterprise mobile applications often include more data-entry-intensive screens and more screen transitions than regular consumer applications. Also the data in a mobile phone is required to be in sync with the data in a back-end server. Due to the limitation in memory capacity for low-end devices, the application design must be highly optimized to avoid any out-of-memory errors during application usage.

This session closely examines the challenges and offers solutions for memory management issues, based on the experience of implementing a field force automation solution for emerging markets.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Experion Presentation at JavaOne 2011: Memory optimizing Java ME applications

  1. 1. Memory Optimizing Java MEapplicationsSreekumar Pillai , CTO, Experion
  2. 2. Java ME Platform§ Java ME devices often are consumer devices which has resource constraints§ Mobile devices are not small PCs§ Applications are to make best use of the available resources§ Development requires a different mindset which expects unexpected things !
  3. 3. Why memory optimization?§ Functionality is often given priority in initial phases of development§ Performance tuning takes a backseat and generally developers ignore efficient usage of memory§ Memory issues are hard to fix§ In Java ME this can be fatal and midlet may not run at all
  4. 4. Java ME Enterprise applications§ Enterprise applications are mostly used by staff to perform operations while they are on Field§ Typically such applications require to connect to a backend server for data access§ Volume of data can be a bottleneck and requires careful design and optimization
  5. 5. Java ME Memory architecture§ Automatic memory management is part of JVM§ Heap -  Heap is created by JVM at startup -  Class instances are allocated in Heap -  Size of Heap is typically fixed to 2Mb (low end devices)§ Garbage Collection -  JVM Specification mandates a garbage collection mechanism -  Programmer is not allowed to explicitly deallocate the memory of an object
  6. 6. Garbage collection§ There is no concept of a pointer in Java§ Memory management is left to JVM§ GC is provided by JVM to reclaim the unreferenced memory§ An object is eligible for garbage collection if it can not be accessed by any live thread
  7. 7. Detecting memory issues§ Exceptions -  JVM Throws OutOfMemoryError -  When trying to allocate more memory than available as a single chunk§ Memory Profiler -  See the objects being allocated and the memory they occupy -  Set the available amount of memory and stress the application
  8. 8. Memory profiler
  9. 9. Memory profiler
  10. 10. How do we optimize ?
  11. 11. Object allocations§ Use as few as possible§ Dereference objects(set to NULL) to enable GC§ Reuse objects§ Heap fragmentation -  See the possibility of doing large allocations first§ Catch OutOfMemoryError for large allocations
  12. 12. Reorganize UI Navigation§ Having more UI elements in a single screen increases the memory requirment§ Good to reduce the data presented in a single screen§ Long lists & scrolling does not result in good user experience§ Split the data into multiple screens ( e.g. a product catalogue can be splitted into category, sub category, and item screens )
  13. 13. Data representations§ XML -  XML is suitable for hierarchical data like a product catalogue -  XML is lengthy and occupies more bandwidth§ JSON -  Simple than XML -  More popular among developers§ CSV / Custom Fixed length -  Full control over data format and parsing
  14. 14. XML Vs JSON<widget> {"widget": { <debug>on</debug> "debug": "on", "window": { <window title="Sample Konfabulator Widget"> "title": "Sample Konfabulator Widget", <name>main_window</name> "name": "main_window", <width>500</width> "width": 500, <height>500</height> "height": 500 </window> }, "image": { <image src="Images/Sun.png" name="sun1"> "src": "Images/Sun.png", <hOffset>250</hOffset> "name": "sun1", <vOffset>250</vOffset> "hOffset": 250, <alignment>center</alignment> "vOffset": 250, "alignment": "center" </image> }, <text data="Click Here" size="36" style="bold"> "text": { <name>text1</name> "data": "Click Here", <hOffset>250</hOffset> "size": 36, <vOffset>100</vOffset> "style": "bold", <alignment>center</alignment> "name": "text1", "hOffset": 250, <onMouseUp> "vOffset": 100, sun1.opacity = (sun1.opacity / 100) * 90; "alignment": "center", </onMouseUp> "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" </text> }</widget> }}
  15. 15. Optimizing XML / JSON§ Reduce size of tags / keys § <Product code>PT1432</Product code>§ Reduce the number of fields required in client side -  Very generalized web services is an overhead for client applciations§ Parsers are memory intensive - For large data strings alternate options to be considered
  16. 16. RMS - Alternate storage§ RMS RecordStore can be used for storing data when size is high§ RecordStore can be addressed using a name tag§ Organize data – Read required information into memory
  17. 17. JAR Size§ Reduce size of classes -  Use an obfuscator to minimize the size of classes§ Themes -  Do you require multiple themes ?§ Images -  Minimize resource sizes -  Use fewer colors as possible
  18. 18. Thank you ...