finnvoor / fx-upscale

Metal-powered video upscaling
Creative Commons Zero v1.0 Universal
311 stars 10 forks source link

Memory leak #22

Closed kevinmore closed 2 hours ago

kevinmore commented 5 hours ago

Hi, I'm trying to use the Upscalar to upscale a video stream to 4K at real time. I noticed a significant memory leak.

My assumption is that the the CVMetal textures are not released properly in the upscaleCommandBuffer function.

Stack trace:

IOSurfaceClientCreateChild  
-[IOSurface initWithProperties:]    
IOSurfaceCreate 
CVPixelBufferBacking::performStandardMemoryLayoutAndCopyIOSurfaceCreationProperties(void*, unsigned char, __CFAllocator const*, __CFDictionary const*, __CFDictionary const*, __CFDictionary const*, __CFDictionary const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, void**, unsigned long*, unsigned long*, unsigned long*, unsigned long*, unsigned long*, __IOSurface**, __IOSurface*, __CVBuffer*, unsigned int*, unsigned long*, void**, __CFDictionary const**)  
_CVPixelBufferStandardMemoryLayout(void*, __CFAllocator const*, __CFDictionary const*, __CFDictionary const*, __CFDictionary const*, __CFDictionary const*, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, void**, unsigned long*, unsigned long*, unsigned long*, unsigned long*, unsigned long*, __IOSurface**, __IOSurface*, __CVBuffer*, unsigned int*, unsigned long*, void**)  
CVPixelBufferBacking::initWithPixelBufferDescription(unsigned long, unsigned long, void*, unsigned long, unsigned long, unsigned long, void**, unsigned long*, unsigned long*, unsigned long*, void (*)(void*, void const*), void (*)(void*, void const*, unsigned long, unsigned long, void const**), void*, __CFDictionary const*, __CFDictionary const*, __IOSurface*, __IOSurface*, __CVBuffer*, unsigned long*, int*)  
CVPixelBufferPool::createPixelBuffer(__CFAllocator const*, __CFDictionary const*, int*) 
CVPixelBufferPoolCreatePixelBuffer  
closure #1 in implicit closure #1 in Upscaler.upscaleCommandBuffer(_:pixelBufferPool:outputPixelBuffer:)    
Upscaler.upscale(_:pixelBufferPool:outputPixelBuffer:)  

Profiling screenshot here:

Screenshot 2024-11-15 at 18 41 01
kevinmore commented 2 hours ago

Silly me. In my case, I need to wrap the upscale() call into an auto realse pool. Closing it now, thanks!

autoreleasepool {
    upscale()
}