Skip to main content

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.

Destructable

A Destructable can be either:

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:

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

  1. Task Creation
  1. Connection Management
  1. Memory Optimization
Always use task labels in debug mode to track task lifecycles and identify potential memory leaks.