Skip to content

cancelCleanUp ​

Cancel Cleanup Task ​

cancelCleanUp is an instance method of the SUDRT protocol. It is used to immediately abort the currently running disk space cleanup or temporary file maintenance task. When the App realizes that the user is about to enter a game session, or when it needs to immediately claim a large amount of IO resources, it can call this method to stop the background cleanup process, ensuring game runtime performance.


Method Declaration ​

objectivec
/**
 * Cancels any active file cleanup or maintenance task currently in progress.
 * After the call, the completion callback of cleanUpExpiredTemporaryFiles: will be triggered.
 */
- (void)cancelCleanUp;

Runtime Behavior ​

  1. Immediate interruption: The engine stops traversing the file system and no longer performs subsequent delete (unlink) operations.
  2. Callback triggering: If cleanUpExpiredTemporaryFiles:start:progress:completion: was called previously, its completion closure immediately receives an NSError containing "task cancelled" information (typically a specific error code).
  3. Resource protection: Files that have already been deleted cannot be recovered, but files that have not yet been processed remain unchanged until the next cleanup task starts.
  4. Statelessness: This method can be safely called when no cleanup task is running, in which case it has no side effects.

Code Example ​

Before a game is about to start, ensure that no background IO task interferes with performance:

objectivec
- (void)prepareForGameStart {
    // 1. Stop any potential cleanup task to free up disk IO
    [self.sdkInstance cancelCleanUp];
    
    // 2. Then execute the game creation logic
    [self.sdkInstance createGameHandleWithOptions:opts completion:^(id handle, NSError *error) {
        // ...
    }];
}

Notes ​

  • Thread safety: Can be called on any thread; the SDK internally synchronizes its state machine to ensure the cleanup thread exits safely.
  • Not a forced destroy: This method targets only the "cleanup task". It does not stop game downloads (loadPackage) or game runtime (stop).
  • Best practice: It is recommended to proactively call this method in low-power mode or when the user's device is overheating, to reduce the system load.