destroy
Task Handle Destruction
destroy is a core instance method of the SUDOPGameTask protocol. It serves as the "abort switch" for asynchronous tasks (such as game preloading, resource downloading, and environment initialization), used to immediately release the associated system resources when a task is no longer needed. When an App page is destroyed or the user actively cancels loading, calling this method ensures that background tasks do not continue to consume memory and bandwidth.
Method Declaration
objc
/**
* Cancels the currently running task and releases all associated hardware and memory resources.
* After the call, the task instance enters an invalid state.
*/
- (void)destroy;Runtime Behavior
- Immediate interruption: The engine sends an interrupt signal to the underlying layer, stopping the execution of the current task's code logic and network I/O transmission.
- Resource reclamation: Triggers the underlying engine to release the occupied GPU textures, audio buffers, file handles, and memory space.
- State invalidation: Once called, the Task instance is declared discarded. Subsequent attempts to perform operations through this instance are intercepted or ignored by the SDK.
- Silent destruction: The destruction process typically does not trigger the original task's "success" callback, but may trigger an error callback containing "cancelled" information.
Code Example
When the user leaves the game page, ensure the preload task is destroyed promptly to conserve performance:
objc
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// 1. If the preload task is still in progress, destroy it immediately
if (self.preloadTask) {
[self.preloadTask destroy];
// 2. Set the handle to nil to prevent delayed release under ARC
self.preloadTask = nil;
}
}Notes
- Memory management: After calling
destroy, be sure to manually set the property holding the object tonil. This is the best practice to ensure the instance is reclaimed promptly and to prevent memory leaks caused by strong references. - Idempotency: This method supports being called multiple times. If the task has already been destroyed, calling
destroyagain has no side effects and does not cause a crash. - Independence:
destroytargets only the task represented by the current Task handle. It does not stop an already-running game instance or affect the global SDK state.
