-
Notifications
You must be signed in to change notification settings - Fork 806
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
Fixing more UIKit memory leaks #1863
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37255db
Fixing leak in UIKit.Xaml controls, and a leak in UIButton.
jaredhms 5e9999d
Adding UIButton memory leak tests.
jaredhms 157b9d6
Switching to fancy new event helper.
jaredhms bfd4c11
Add a slight delay after freeing the UIBUtton to prevent a very inter…
jaredhms 82d0fb8
Switching to StrongId for VC.
jaredhms 8e376a5
Incorporating CR feedback.
jaredhms 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,63 @@ | |
ASSERT_TRUE([backingElement isKindOfClass:[WXFrameworkElement class]]); | ||
} | ||
|
||
@interface UIDeallocTestButton : UIButton { | ||
std::shared_ptr<UXEvent> _event; | ||
} | ||
@end | ||
|
||
@implementation UIDeallocTestButton | ||
|
||
- (void)setDeallocEvent:(std::shared_ptr<UXEvent>)event { | ||
_event = event; | ||
} | ||
|
||
-(void)dealloc { | ||
_event->Set(); | ||
[super dealloc]; | ||
} | ||
@end | ||
|
||
TEST(UIButton, CheckForLeaks) { | ||
Microsoft::WRL::WeakRef weakXamlElement; | ||
{ | ||
__block UIButtonWithControlsViewController* buttonVC = [[UIButtonWithControlsViewController alloc] init]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I might have missed this before but do you really need __block here. I am under the impression, it should be retained correctly. #Resolved |
||
UXTestAPI::ViewControllerPresenter testHelper(buttonVC); | ||
|
||
__block UIDeallocTestButton* testButton = nil; | ||
__block auto event = UXEvent::CreateAuto(); | ||
|
||
// Create and render the button | ||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
testButton = [[UIDeallocTestButton alloc] initWithFrame:CGRectMake(100, 100, 100, 100)]; | ||
testButton.backgroundColor = [UIColor redColor]; | ||
[testButton setDeallocEvent:event]; | ||
[buttonVC.view addSubview:testButton]; | ||
}); | ||
|
||
// Grab a weak reference to the backing Xaml element | ||
Microsoft::WRL::ComPtr<IInspectable> xamlElement([[testButton xamlElement] comObj]); | ||
ASSERT_TRUE_MSG(SUCCEEDED(xamlElement.AsWeak(&weakXamlElement)), "Failed to acquire a weak reference to the backing Xaml element."); | ||
xamlElement = nullptr; | ||
|
||
// Free the button | ||
dispatch_sync(dispatch_get_main_queue(), ^{ | ||
// Nil out testButton and remove it from its superview | ||
[testButton removeFromSuperview]; | ||
[testButton release]; | ||
testButton = nil; | ||
}); | ||
|
||
// Validate that dealloc was called | ||
ASSERT_TRUE_MSG(event->Wait(c_testTimeoutInSec), "FAILED: Waiting for dealloc call failed!"); | ||
} | ||
|
||
// Validate that we can no longer acquire a strong reference to the UIButton's backing Xaml element | ||
Microsoft::WRL::ComPtr<IInspectable> xamlElement; | ||
weakXamlElement.As(&xamlElement); | ||
ASSERT_EQ_MSG(xamlElement.Get(), nullptr, "Unexpectedly able to reacquire a strong reference to the backing Xaml element."); | ||
} | ||
|
||
TEST(UIButton, TitleColorChanged) { | ||
__block auto uxEvent = UXEvent::CreateManual(); | ||
__block auto xamlSubscriber = std::make_shared<XamlEventSubscription>(); | ||
|
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.
Your real problem is the XamlCreateButton api design. If it returned HRESULT and an out pointer, you have to try hard to leak it. With the current model, it is easy to mess it up. #Resolved
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.
I suppose an out param would make it a bit more difficult to leak.
In reply to: 98310272 [](ancestors = 98310272)