# Performance

# Garbage Collection

In the Mini Game, each Canvas or Image object in JavaScript will have a client-side actual texture storage. The actual texture storage stores the real textures of Canvas and Image, which usually occupy a considerable portion of memory. The recycling time of each client's actual texture storage depends on the recycling of Canvas and Image object in JavaScript. Before Canvas and Image objects in JavaScript are reclaimed, the actual texture storage corresponding to the client will not be reclaimed. By calling the wx.triggerGC(), you can speed up the triggering of the JavaScriptCore Garbage Collection (Garbage Collection), which triggers the recycling of Canvas and Image that is not referenced in JavaScript and release the corresponding actual texture storage. However, the specific trigger timing of the GC depends on the JavaScriptCore mechanism itself,which cannot guarantee that the call to wx.triggerGC() can immediately trigger recovery. It is recommended to trigger at the start or end of each game.

# Mixed Rendering Mode

In some mixed rendering mode games, the game scene uses WebGL's mode for rendering, but some GUIs and leaderboards and other content are rendered using the canvas 2d mode.

In the original logic, you need to use the gl.texImage2d interface to render.

gl.texImage2D(target, level, internalformat, format, type, canvas)

Each time you update the canvas, you need to call the interface again.

To solve this problem, we introduced a new method of WebGLRenderingContext.wxBindCanvasTexture() on the gl context. This method takes a canvas as a parameter and binds the corresponding texture of the canvas to gl.

gl.wxBindCanvasTexture(gl.TEXTURE_2D, canvas)

After that, only Canvas updating is needed.

Currently this method only supports versions of iOS 6.6.6 and above, Android/Developer Tools are not supported for the time being.

点击咨询小助手