Skip to content

Release all images in MetalTextureHandler::releaseRenderResources#2316

Merged
jstone-lucasfilm merged 3 commits intoAcademySoftwareFoundation:mainfrom
ld-kerley:release-all-imagesin-releaseRenderResources
Mar 27, 2025
Merged

Release all images in MetalTextureHandler::releaseRenderResources#2316
jstone-lucasfilm merged 3 commits intoAcademySoftwareFoundation:mainfrom
ld-kerley:release-all-imagesin-releaseRenderResources

Conversation

@ld-kerley
Copy link
Copy Markdown
Contributor

This PR addresses #2303.

This brings the MetalTextureHandler inline with the GLTextureHandler for releasing all the images when nullptr is passed.

Without this - both CPU and Metal texture memory is being leaked if the image caches are flushed.

Recursively releasing the resources fixes the Metal texture memory leak, but that just highlighted the CPU side memory leak. This is due to the MetalTextureHandler also retaining an ImagePtr in _imageBindingInfo. Removing the ImagePtr from this storage fixes the memory leak, and it doesn't seem to be necessary to store the image, the only thing the image is used for is to access the resource ID - which is the same as the key to the unordered_map.

…ePtr - which was causing memory leak.

Refactoring to only store the ImageSamplingProperties - getMTLTextureForImage() refactor is ok, because the index for _imageBindingInfo is exactly the image->getResourceId()
@ld-kerley ld-kerley force-pushed the release-all-imagesin-releaseRenderResources branch from a728c49 to 7395313 Compare March 27, 2025 15:21
@jstone-lucasfilm jstone-lucasfilm changed the title Release all images in releaseRenderResources() Release all images in MetalTextureHandler::releaseRenderResources Mar 27, 2025
@jstone-lucasfilm jstone-lucasfilm changed the title Release all images in MetalTextureHandler::releaseRenderResources Release all images in MetalTextureHandler::releaseRenderResources Mar 27, 2025
Copy link
Copy Markdown
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thanks @ld-kerley!

@jstone-lucasfilm jstone-lucasfilm merged commit 6ce8fd0 into AcademySoftwareFoundation:main Mar 27, 2025
35 checks passed
@ld-kerley ld-kerley deleted the release-all-imagesin-releaseRenderResources branch November 21, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants