andormarkus commented on issue #2325:
URL: 
https://github.com/apache/iceberg-python/issues/2325#issuecomment-3215615700

   I have implemented manual clearing of the `_manifests` cache but the memory 
leak persists in AWS Lambda.
   
   **Environment:** AWS Lambda, PyIceberg with Glue catalog
   
   **Cache Clearing Implementation:**
   ```python
   def cleanup(self):
       """Clear PyIceberg cachetools LRUCache to prevent memory leaks"""
       try:
           # Clear the specific cachetools LRUCache that's causing the memory 
leak
           import pyiceberg.manifest as manifest_module
           
           # The _manifests function has @cached(cache=LRUCache(maxsize=128))
           if hasattr(manifest_module, '_manifests'):
               manifests_func = getattr(manifest_module, '_manifests')
               # cachetools @cached decorator stores cache in the function
               if hasattr(manifests_func, 'cache'):
                   cache_size = len(manifests_func.cache)
                   manifests_func.cache.clear()
                   logger.info(f"Cleared PyIceberg manifest cache ({cache_size} 
entries)")
                           
       except Exception as e:
           logger.warning(f"Could not clear PyIceberg cache: {e}")
       
       # Clean up objects
       if hasattr(self, 'catalog'):
           del self.catalog
       if hasattr(self, 'client'):
           del self.client
       gc.collect()
   ```
   
   **Results:** Memory still grows from 1438MB → 1858MB across invocations. The 
manifest cache clearing had minimal impact.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to