Technical Reference
Detailed technical specifications and implementation details
Technical Reference
Type Definitions
SweepTask
A SweepTask can be any of the following:
SweepTasks are the fundamental unit of cleanup in the Sweep framework. They can be functions, objects, connections, or threads.
Type | Description |
---|---|
Function | A function that can be called for cleanup |
Destructable | Instance or object with Destroy method |
RBXScriptConnection | RBXScriptConnection |
thread | Coroutine |
Destructable
A Destructable can be either:
- A Roblox Instance
- Any object with a Destroy method
Internal Implementation Details
Task Storage
Tasks are stored internally in the Sweep instance using two main tables:
Task Indexing
Tasks use a numerical indexing system:
- Tasks are indexed numerically starting from 1
- Each task gets a unique ID returned by
GiveTask
- Labels are stored with the same index as their corresponding task
Memory Management
Garbage Collection
The framework handles cleanup through several mechanisms:
- Tasks are properly dereferenced when cleaned
- Connections are explicitly disconnected
- Objects are destroyed using their Destroy method
- Threads are cancelled using task_cancel
Connection Handling
Debug System
Debug Mode
Debug mode is controlled through ReplicatedStorage:
Debug Information
When enabled, the system logs:
- Task creation and deletion
- Memory usage (via gcinfo())
- Stack traces for important operations
- Task type information
- Connection states
- Thread states
Debug Logging
The debug system provides detailed logging for:
Operation | Information Logged |
---|---|
Task Creation | Timestamp, task type, label |
Task Cleanup | Timestamp, cleanup duration |
Memory Usage | Current memory usage, changes |
Task Execution | Start time, end time, duration |
Connection States | Connected, disconnected events |
Thread Management | Thread creation, completion |
Promise Resolution | Resolution time, state |
Advanced Usage
Custom Task Types
You can extend Sweep with custom task types:
Promise Integration
The Promise integration handles different promise states:
Interval Task Implementation
Performance Considerations
Memory Usage
Optimize memory usage by cleaning up tasks as soon as they’re no longer needed.
Key considerations:
- Each task requires minimal overhead (just table entries)
- Labels add additional memory overhead per task
- Debug mode increases memory usage due to logging
CPU Usage
Performance characteristics:
- Task cleanup is performed sequentially
- Connections are prioritized in cleanup
- Interval tasks run on separate threads
- Promise resolution is asynchronous
Best Practices
- Task Creation
- Connection Management
- Memory Optimization
Always use task labels in debug mode to track task lifecycles and identify potential memory leaks.