Use a ReferenceQueue to prune weak references
Currently ResourcesManager iterates over all of its weak references to Resources objects and calls Reference#get to determine if the object has been garbage collected. This method of pruning WeakReferences causes reference locks to be acquired in the native layer and causes lock contention when "references are being processed" by the garbage collector. This change uses a ReferenceQueue to determine if a reference has been garbage collected which should improve performance of ResourcesManager#getResources when the system is under memory pressure. By only removing garbage collected references when creating new Resources objects, the lists grow larger and are periodically pruned rather than attempting to prune entries from the list every getResources invocation. Bug: 157575833 Test: used debugger to observe pruning happening correctly hange-Id: I3277e80edfa441d24de165e738d33c4fac6b4121 Change-Id: I3277e80edfa441d24de165e738d33c4fac6b4121
Loading
Please register or sign in to comment