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
Loading
Please register or sign in to comment