Task Manager
SUDOPGameTask is the class in the SDK responsible for lifecycle control of long-running asynchronous tasks. It allows the APP to perform on-demand operations on ongoing background operations (such as game package downloads, environment warm-up, resource extraction, etc.) to terminate tasks and release resources. Through this class, developers can flexibly and effectively address memory leaks or bandwidth waste caused by asynchronous tasks on demand.
Core Management Mechanisms
1. Task Handle
When the APP calls an SDK asynchronous interface (for example, preloadGame:), the SDK immediately returns an object that implements the SUDOPGameTask protocol.
- Internal management: The SDK internally holds and maintains the task, ensuring that the executing task runs to full completion.
- Immediate return: Even if the task is still in the network request phase, the handle is returned to the APP first.
- Unique identifier: Each handle corresponds to an independent task instance, without interfering with one another.
2. Controlled Lifecycle
Tasks are no longer "fire and forget" logic; the APP has the final say:
- Active termination: By calling the
destroymethod, the APP can cut off a task at any time. - Resource alignment: A task's lifecycle should be aligned with the APP's UI components (such as an
Activity), ensuring "interface closed, task stopped."
Runtime Behavior
- State truncation: Once a management instruction (destroy) is executed, the SDK's internal state machine immediately marks the task as
Cancelled. - I/O release:
- Network layer: Immediately disconnects the data stream being downloaded and stops occupying bandwidth.
- Disk layer: Stops writing temporary files and cleans up unfinished fragments.
- Memory layer: Releases textures, models, or audio buffers preloaded into memory.
- Callback closure: After a task is destroyed via management, the original "success" callback will no longer fire, avoiding crashes (Bad Access) caused by performing UI updates after the page is destroyed.
Notes
- Memory management:
If the invoked interface has a listener callback, it is recommended to hold that object and call
destroyat the necessary moment to destroy the task. This is the best practice for ensuring the instance is reclaimed promptly and preventing memory leaks caused by strong references.If you do not care about the task handle, you can set the listener to null to avoid memory leaks caused by the listener callback strongly holding the related instance.
- Idempotency: This method supports being called multiple times. If the task has already been destroyed, calling
destroyagain produces 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.
