Experion Presentation at JavaOne 2011: Memory optimizing Java ME applications
-
Upload
experion-technologies -
Category
Technology
-
view
664 -
download
0
description
Transcript of Experion Presentation at JavaOne 2011: Memory optimizing Java ME applications
Memory Optimizing Java ME applications Sreekumar Pillai , CTO, Experion
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 !
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
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
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
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
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
Memory profiler
Memory profiler
How do we optimize ?
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
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 )
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
XML Vs JSON <widget> <debug>on</debug> <window title="Sample Konfabulator Widget"> <name>main_window</name> <width>500</width> <height>500</height> </window> <image src="Images/Sun.png" name="sun1"> <hOffset>250</hOffset> <vOffset>250</vOffset> <alignment>center</alignment> </image> <text data="Click Here" size="36" style="bold"> <name>text1</name> <hOffset>250</hOffset> <vOffset>100</vOffset> <alignment>center</alignment> <onMouseUp> sun1.opacity = (sun1.opacity / 100) * 90; </onMouseUp> </text> </widget>
{"widget": { "debug": "on", "window": { "title": "Sample Konfabulator Widget", "name": "main_window", "width": 500, "height": 500 }, "image": { "src": "Images/Sun.png", "name": "sun1", "hOffset": 250, "vOffset": 250, "alignment": "center" }, "text": { "data": "Click Here", "size": 36, "style": "bold", "name": "text1", "hOffset": 250, "vOffset": 100, "alignment": "center", "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" } }}
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
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
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
Thank you ...