void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                EffectUtilities.UnregisterEffectControlProvider(this, Element);

                if (Element != null)
                {
                    Element.PropertyChanged -= OnElementPropertyChanged;
                }

                if (_renderer != null)
                {
                    _renderer.ElementChanged         -= OnElementChanged;
                    _renderer.ElementPropertyChanged -= OnElementPropertyChanged;
                    _renderer = null;
                }

                _gestureManager?.Dispose();
                _automationPropertiesProvider?.Dispose();
            }
        }
Example #2
0
        protected override void Dispose(bool disposing)
        {
            if (CheckFlagsForDisposed())
            {
                return;
            }

            _flags |= VisualElementRendererFlags.Disposed;

            if (disposing)
            {
                SetOnClickListener(null);
                SetOnTouchListener(null);

                EffectUtilities.UnregisterEffectControlProvider(this, Element);

                if (Tracker != null)
                {
                    Tracker.Dispose();
                    Tracker = null;
                }

                if (_packager != null)
                {
                    _packager.Dispose();
                    _packager = null;
                }

                if (_gestureManager != null)
                {
                    _gestureManager.Dispose();
                    _gestureManager = null;
                }

                if (ManageNativeControlLifetime)
                {
                    int count = ChildCount;
                    for (var i = 0; i < count; i++)
                    {
                        AView child = GetChildAt(i);
                        child.Dispose();
                    }
                }

                if (Element != null)
                {
                    Element.PropertyChanged -= _propertyChangeHandler;

                    if (Platform.GetRenderer(Element) == this)
                    {
                        Platform.SetRenderer(Element, null);
                    }

                    Element = null;
                }
            }

            base.Dispose(disposing);
        }