addObject method

Future<void> addObject(
  1. Object value
)

Implementation

Future<void> addObject(Object value) async {
  if (_gcRunning) {
    return;
  }

  // Limit the number of tracked objects for production stability
  if (_weakReferenceList.length >= _maxTrackingObjects) {
    _performCleanup();
    if (_weakReferenceList.length >= _maxTrackingObjects) {
      return; // Skip tracking if still at limit after cleanup
    }
  }

  if (Platform.isAndroid || Platform.isIOS) {
    _addObjectToList(value);
  }

  // Periodic cleanup to prevent memory buildup
  _addedCount++;
  if (_addedCount % _cleanupInterval == 0) {
    _performCleanup();
  }
}