KVHeavyTaskDataProviderStopAction
public enum KVHeavyTaskDataProviderStopAction
Defines the action to take when a DataProvider is stopped during task interruption.
This enum controls the lifecycle management of DataProvider instances when they are interrupted by higher-priority tasks in LIFO(.stop) strategy. The choice between reuse and dealloc affects memory usage, performance, and task resumption behavior.
Performance Implications
- Reuse: Lower memory allocation overhead, faster task resumption, higher memory usage
- Dealloc: Higher allocation overhead, slower resumption, lower memory footprint
Use Case Guidelines
- Choose reuse for tasks that are likely to resume soon or have expensive setup
- Choose dealloc for tasks with large memory footprint or unlikely to resume
-
Keep the DataProvider instance in memory for potential future resumption.
When to use:
- Tasks with expensive initialization (network connections, file handles, parsed data)
- Frequently interrupted tasks that need quick resumption
- Tasks where preserving intermediate state provides significant performance benefits
Trade-offs:
- ✅ Faster resumption (no re-initialization required)
- ✅ Preserves computed intermediate results and state
- ❌ Higher memory usage (provider remains in memory)
- ❌ Potential memory leaks if tasks never resume
Declaration
Swift
case reuse
-
Deallocate the DataProvider instance to free memory immediately.
When to use:
- Tasks with large memory footprint (large buffers, cached data, heavy objects)
- Rarely resumed tasks or one-time operations
- Memory-constrained environments where immediate cleanup is preferred
Trade-offs:
- ✅ Immediate memory reclamation and cleanup
- ✅ Prevents potential memory leaks from abandoned tasks
- ❌ Slower resumption (requires full re-initialization)
- ❌ Loss of intermediate results and computed state
Declaration
Swift
case dealloc