ImageSource Memory Management for Android Bitmap Reclamation
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
In resource-constrained devices, such as Android-based applications, image memory allocated from unmanaged memory is not frequently reclaimed by the garbage collector, leading to memory exhaustion and application restarts, as bitmap objects holding onto large image memory blocks are not promptly freed.
Innovation Solution
Implementing an ImageSource class that manages image memory by using a binding object to an ImageView, with lifecycle methods for creation, destruction, binding, and unbinding, and employing weak references to enable the garbage collector to reclaim unmanaged memory when images are no longer visible, ensuring that image memory is visible to the heap manager and can be quickly freed.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If image memory is allocated from unmanaged memory, then the garbage collector cannot reclaim the memory, but this leads to memory exhaustion and application restarts
Solution Approach 1:
The patent segments memory management into two distinct portions: managed memory for control structures (ImageSource, binding objects, ImageView references) and unmanaged memory for actual image data storage. This segmentation allows the garbage collector to manage the control structures and detect when they are no longer needed, while the unmanaged memory can be efficiently allocated and freed based on garbage collection events, resolving the contradiction between memory stability and available memory.
2Reliability
If bitmap objects hold onto large image memory blocks, then memory is retained for potential reuse, but this prevents timely memory reclamation and causes memory exhaustion
Solution Approach 1:
The patent implements a feedback mechanism where the binding object monitors the visibility state of images through lifecycle methods. When an image is no longer visible (unbind called), the binding object notifies the ImageSource, which then triggers garbage collection. This feedback loop ensures that memory is reclaimed promptly when no longer needed, resolving the contradiction between maintaining memory availability and enabling timely reclamation.
Solution Approach 2:
The ImageSource and binding objects automatically manage their own memory lifecycle without requiring external intervention. The binding object detects when it is no longer bound to an ImageView and automatically initiates the memory reclamation process by allowing the ImageSource to be garbage collected, which in turn frees the unmanaged memory. This self-service approach eliminates delays associated with manual memory management.
3Ease of operation
If a dynamic view architecture with garbage collection is used, then memory can be automatically managed, but this increases system complexity
Solution Approach 1:
The patent introduces a binding object as an intermediary between the ImageSource (managed memory) and the unmanaged image data. This binding object serves as a mediator that manages the relationship and lifecycle coordination between managed and unmanaged portions. By inserting this intermediary layer, the system achieves automated memory management through garbage collection while maintaining a clear separation of concerns, thus managing complexity rather than simply increasing it.
Data Source
AI summary
Disclosed are apparatus and methods for managing image storage. An image source of a computing device can include one or more functions and a reference to image views for an image object, such as a bitmap object. The image object can include a reference to first storage that stores an image. The image source, the reference to the image views, and the image object are stored in a managed portion of memory. The first storage is stored in an unmanaged portion of memory differing from the managed portion. The computing device displays the image. Upon determining to discontinue displaying the image, an unbind function of the image source is called. The image source responsively discontinues display of the image. The image source receives an indication that the image views are solely weakly referenced. In response to the indication, the image source deallocates the first storage.


