processForLeaks method

void processForLeaks(
  1. int index
)

Implementation

void processForLeaks(int index) async{
  if (weakReferenceList.isEmpty) return;
  if(gcRunning) return;
  gcRunning = true;
  debugPrint('Index $index and list length ${weakReferenceList.length}');

  List<int> keysToBeRemoved = [];
  Iterator<int> iterator = weakReferenceList.keys.iterator;
  while (iterator.moveNext()) {
    int currentKey = iterator.current;
    debugPrint('Current key $currentKey and index $index');
    if(currentKey > index){
      break;
    }

    WeakReference? weakReferenceItem = weakReferenceList[currentKey];
    if(weakReferenceItem == null) {
      debugPrint('Item not available $currentKey');
      continue;
    }

    if (weakReferenceItem.target != null) {
      //Raise leak issue.
      debugPrint('leak found ${weakReferenceItem.target}');

      FinotescorepluginPlatform.instance.memoryLeakReported(
          weakReferenceItem.target.runtimeType.toString(),
          weakReferenceItem.target.toString());

    }else{
      debugPrint('No leak found $currentKey');
    }
    keysToBeRemoved.add(currentKey);

  }

  for (var keyToBeRemoved in keysToBeRemoved) {
    weakReferenceList.remove(keyToBeRemoved);
  }

  // for (int key = 0; key <= weakReferenceList.keys.le; key++){
  //   WeakReference? weakReferenceItem = weakReferenceList[key];
  //   if (weakReferenceItem.target != null) {
  //     //Raise leak issue.
  //     debugPrint('leak found ${weakReferenceItem.target}');

  //     // FinotescorepluginPlatform.instance.memoryLeakReported(
  //     //     weakReferenceItem.target.runtimeType.toString(),
  //     //     weakReferenceItem.target.toString());

  //   }else{
  //     debugPrint('No leak found $i');
  //   }
  //   // weakReferenceList.removeAt(i); //If removed then the index and length will cause clash.
  // }
  gcRunning = false;
}