title: creator-js articles on leak detection
categories: Cocos2dx
tags: [creator, optimization, leak, memory]
date: 2023-03-28 16:16:49
comments: false
mathjax: true
toc: true
creator-js articles of leak detection
Prequel
- In fact, the method is the same as the previous egret_memory analysis-leakage.md
Use ui as a test. Under normal circumstances, open and close a ui repeatedly, and the ui instance is to be recycled
Test 01 - Normal Recovery
-
Here are 3 snapshots, 1 is that the ui is not loaded, 2 is that the ui is loaded, and 3 is that the ui is destroyed
-
Compare snapshot 2 with snapshot 1
After loading ui, add a ui instance (UIPnlxxx is the prefix of the UI class name)
-
Compare snapshot 3 with snapshot 2
After destroying ui, one ui instance is reduced
-
Compare snapshot 3 with snapshot 1
There is no ui instance, indicating that the ui instance object has been recycled normally
Test 02 - Simulated Leak
-
Deliberately register events when ui is initialized, so that the event system can refer to this instance
-
The ui operation is the same as above, directly compare snapshot 3 with snapshot 1
It can be seen that the ui instance has not been destroyed. If you continue to open and destroy the ui repeatedly, you can see that this number will keep increasing, indicating a leak
-
Expand this ui class, click on the ui instance, you can see the reference chain of this ui instance in the Retainers column below, and you can see that it is referenced by the event system