java icon indicating copy to clipboard operation
java copied to clipboard

separate initial load to avoid retaining list items in memory

Open rafaelri opened this issue 4 months ago • 5 comments
trafficstars

Local variables list and items will retain the list of objects returned in the initial list in the heap while the Thread that is running run is alive. Leading to a minor but still a leak since those objects could be collected if the local variable was made out of scope. This PR separates the initial load in a separate method that returns the resourceVersion and shortens the scope of the variables mentioned to allow garbage collection.

 ApiListType list =
          listerWatcher.list(
              new CallGeneratorParams(Boolean.FALSE, getRelistResourceVersion(), null));

      V1ListMeta listMeta = list.getMetadata();
      String resourceVersion = listMeta.getResourceVersion();
      List<? extends KubernetesObject> items = list.getItems();

This PR also removes the watcher attribute and replaces the closing logic to release resources as soon as the events on a particular watcher have been processed.

rafaelri avatar Jun 24 '25 22:06 rafaelri