destroy
Destroy the mini game runtime environment
destroy marks the end of the mini game lifecycle. Calling this method completely shuts down the game engine, reclaims all occupied system resources (including JavaScript virtual machine memory, render buffers, thread pools, and texture resources), and resets the instance state to unavailable.
Method Declaration
objectivec
/**
* Destroy the mini game runtime environment.
* After success, the mini game instance enters the `UNAVAILABLE` state.
* After the call, all memory and view resources associated with this handle are released.
*/
- (void)destroy;Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| None | - | - | This method takes no parameters. |
Runtime Behavior
- Resource reclamation: Forcibly stops all running JS scripts and destroys the JSC virtual machine context.
- Render teardown: Releases all GPU texture resources and stops the Metal/OpenGL render loop.
- View cleanup: The view returned by
getGameViewis destroyed. If the view has been added to a parent view, it is recommended to remove it manually before the call, or to nil out the reference after the call. - State transition: After execution, the state becomes
SUD_RT_GAME_STATE_UNAVAILABLE (0). This handle can no longer callcreateorstart.
Example
objectivec
- (void)dealloc {
[self cleanupGame];
}
- (void)cleanupGame {
if (self.gameHandle) {
// 1. It is recommended to stop first and notify the game layer
[self.gameHandle stop:@"{\"reason\":\"dealloc\"}"];
// 2. Fully destroy the environment
[self.gameHandle destroy];
// 3. Remove references and clean up UI
dispatch_async(dispatch_get_main_queue(), ^{
UIView *gameView = [self.gameHandle getGameView];
[gameView removeFromSuperview];
self.gameHandle = nil;
});
}
}Notes
- Memory leak prevention: When the
ViewControlleris destroyed or the user exits the game scene, be sure to calldestroy. Otherwise, the JS engine running in the background and cached textures will cause severe memory accumulation. - Irreversibility: Once
destroyis executed, the currentgameHandleinstance is invalidated. To re-enter the game, you must create a new handle instance and run the full lifecycle again. - Timing: If you are only temporarily switching to the background or presenting a native interface, use
pause; only usedestroywhen you are sure the current game instance is no longer needed. - Thread safety: It is recommended to initiate the destroy instruction on the main thread to keep it in sync with the UI removal operation.
