Skip to content

Conversation

@VincentDondain
Copy link
Contributor

  • Fixes issue Merge xcode8.2 into cycle8-xi #1345: [FAIL] GestureRecognizerTest.NoStrongCycles : Any finalized
    (https://github.com/xamarin/maccore/issues/1345)
  • Because UIGestureRecognizer has an OnDispose () method called by Dispose () it also means we're at some point running GC.SuppressFinalize().
    Therefore, fix the test to also call the delegate when Dispose () is called and not the finalizer only.
    As I understand, the goal of this test is to make sure that the UIGestureRecognizer does not hold FinalizerNotifier, a.k.a that its finalizer / dispose is called.

- Fixes issue dotnet#1345: [FAIL] GestureRecognizerTest.NoStrongCycles : Any finalized
(xamarin/maccore#1345)
- Because `UIGestureRecognizer` has an `OnDispose ()` method called by `Dispose ()` it also means we're at some point running `GC.SuppressFinalize()`.
  Therefore, fix the test to also call the delegate when `Dispose ()` is called and not the finalizer only.
  As I understand, the goal of this test is to make sure that the `UIGestureRecognizer` does not hold `FinalizerNotifier`, a.k.a that its finalizer / dispose is called.
Copy link
Contributor

@stephen-hawley stephen-hawley left a comment

Choose a reason for hiding this comment

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

I don't like all three cases being run in one test, but that's what it was before.

@monojenkins
Copy link
Collaborator

Build failure
Build succeeded
API Diff (from stable)
ℹ️ API Diff (from PR only) (please review changes)
Generator Diff (no change)
🔥 Test run failed 🔥

Test results

1 tests failed, 0 tests skipped, 79 tests passed.

Failed tests

  • monotouch-test/iOS Unified 32-bits - simulator/Debug (static registrar): Failed

@rolfbjarne
Copy link
Member

The initial fix is fixing a strong cycle, so that the GC can collect all the objects in the cycle.

The corresponding test creates such a cycle, and asserts that one of the objects in the cycle is collected. The asserted object (FinalizerNotifier) is a plain managed object (it does not inherit from NSObject), and as such GC.SuppressFinalize() is never called for this object (for is Dispose for that matter, which explains why this fix didn't actually work).

The fact that it only seem to fail on 32-bit is strange, however. It means the test works fine in 64-bit... Maybe one place to start investigating is to check if the RemoveTarget code from the BeginInvokeOnMainThread block is actually called or not: https://github.com/xamarin/xamarin-macios/pull/5402/files#diff-71c27806e4190990d0e094755a9d2b43R49

public void Dispose ()
{
if (Action != null)
Action ();
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be a race condition, not in this case AFAIK. But I find it safer to do Action?.Invoke() since from the check agains null until the execution, Action can be set to be null. Thread stops after the check, other thread changes action, first thread continues and boom! NRE.

Copy link
Contributor

Choose a reason for hiding this comment

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

yup (ToCToU). .net pattern for events suggest a local

var a = Action;
if (a != null)
    a ();

so the check and the call are done on the same value.

Copy link
Contributor

@spouliot spouliot left a comment

Choose a reason for hiding this comment

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

+1 on @rolfbjarne comment

Since this test prevent us from having green builds (and we already have an open issue) this test should be disabled (separate PR) and back ported to d16-0 (while we can)

VincentDondain added a commit to VincentDondain/xamarin-macios that referenced this pull request Jan 25, 2019
- WIP PR dotnet#5462 more investigation needed so ignore test which is preventing green builds
monojenkins pushed a commit to monojenkins/xamarin-macios that referenced this pull request Jan 25, 2019
- WIP PR dotnet#5462 more investigation needed so ignore test which is preventing green builds
VincentDondain added a commit that referenced this pull request Jan 28, 2019
- WIP PR #5462 more investigation needed so ignore test which is preventing green builds
@VincentDondain
Copy link
Contributor Author

Note: when fixed, don't forget to un-ignore the test: #5486

chamons pushed a commit that referenced this pull request Jan 30, 2019
- WIP PR #5462 more investigation needed so ignore test which is preventing green builds
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.

6 participants