Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 26835f0b authored by Garfield Tan's avatar Garfield Tan
Browse files

Track and reset mock to avoid mem leaks.

When a test calls a mock with another mock, it creates a chain of
reference inside MockHandlerImpl because invocation is saved in
invocationContainer for stubbing record. If InlineDexmakerMockMaker, the
MockHandlerImpl is then stored in a mock map to provide stubbing
behavior for future use, and will be cleaned up from the mock map when
the mock object is reclaimed by GC.

Since InlineDexmakerMockMaker only cleans up the map at most once every
16s, we need 16s plus a GC pass to shorten the chain of ref by one node
when the chain doesn't form a ring.

This CL resets all created mocks after running each test suite.
Consequently it uses a brand new MockHandlerImpl to replace the original
one and break down the reference chain.

One thing that's worth noting is this is not a complete solution to this
issue, as the MockCreationListener is held in a ThreadLocal, which means
we can only get notified for mocks created in the same thread, but this
is enough for now because it catches many large retainers like ATMS and
WMS.

Bug: 123984854
Test: atest WmTests can run to the end w/o hanging or crashing. Note
this only fixes one of two memory issues we found in the bug.

Change-Id: Iab08c4a324f4de593323d4914256970d7bc1a150
parent 0528cd9d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment