-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't retain the MTLTexture or MTLDevice in TestMetalContext #30832
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't necessary, those textures are stored in sk_cfp which calls release in its deconstructor. If you see this being necessary you probably have a double retain. It looks correct when you are making it to me, the apis are a bit confusing though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right - I missed that we were calling the
sk_cfp
copy ctor when assigning theMTLTexture
into thetextures_
map (and that thetextures_
map holds thesk_cfp
and not a raw pointer). This means that we don't need to release manually in this dtor, but I believe we still need to remove the extraretain
call, right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, I believe we should have the retain now.
[device newTextureWithDescriptor:texture_descriptor.get()]
should return an object that is on the autorelease pool. Which means it will get released when this event is done, so we'd need a retain to keep it alive in the smart pointer.I'm not 100% certain because the semantics for an objc method called
new*
that return an objc object are a bit unclear to me. I think technically anything that isn't namedcreate
should be on the autorelease pool, but that isn't the case for-[NSObject new]
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I'm misunderstanding the guide at https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html, it says that any ObjC method with "new" in the name returns an object that the caller owns outright. That implies to me that it won't be in the autorelease pool.
That being said, I think that the
MTLTextureDescriptor
does fall under that category perhaps, as the ObjC method name does not include the word "new", "create" etc, so I'd expect that to be in the autorelease pool?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yep, you're right, anything that begins with "new" means the caller owns it. No need to retain it again. You don't run into
new
methods often.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, the unit test that was failing was because the
MTLTextureDescriptor
is indeed returned already in the autorelease pool, so that retain still needs to be there.With that fixed, all the unit tests are now passing locally.