creator-js articles of leak detection


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

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

  1. 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

    image-20230328162537307

  2. Compare snapshot 2 with snapshot 1

    image-20230328162557112

    After loading ui, add a ui instance (UIPnlxxx is the prefix of the UI class name)

  3. Compare snapshot 3 with snapshot 2

    image-20230328162621166

    After destroying ui, one ui instance is reduced

  4. Compare snapshot 3 with snapshot 1

    image-20230328162647950

    There is no ui instance, indicating that the ui instance object has been recycled normally


Test 02 - Simulated Leak

  1. Deliberately register events when ui is initialized, so that the event system can refer to this instance

    image-20230328162731030

  2. The ui operation is the same as above, directly compare snapshot 3 with snapshot 1

    image-20230328162749234

    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

  3. 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

    image-20230328162833823


Guess you like

Origin blog.csdn.net/yangxuan0261/article/details/129819160