Quantcast
Channel: Silverlight Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 801

Commented Issue: TiltEffect keeps a reference to the last item animated, causing a leak [10527]

$
0
0
<p>Subject pretty much explains it.</p>
<p>&nbsp;</p>
<p>In the repro (note that MainPage.xaml is not used):</p>
<p>1. Tap the top button, this will bring up a window,</p>
<p>2. Tap the button on the window (this will do nothing)</p>
<p>3. Go back</p>
<p>4. Tap the clear memory button (bottom)</p>
<p>5. Look at the output window - this will show that the page is leaking.</p>

Comments: ** Comment from web user: uxadditives **

The problem is the use of static properties linked to view elements. Once you link an element of the view with a static property in the TiltEffect, this element cannot be released. See below, I have marked the reason for the memory leak in a code block and show a possible work around to release the element. A better way would be to prevent using a static for the currentTiltElement, but I'm not sure how to do this in this TiltEffect class.

Problem cause

static void BeginTiltEffect(FrameworkElement element, Point touchPoint, Point centerPoint, Point centerDelta)
{
if (tiltReturnStoryboard != null)
{
StopTiltReturnStoryboardAndCleanup();
}

if (PrepareControlForTilt(element, centerDelta) == false)
{
return;
}

//###################
//# RdB - Rob de Beir
//# Note: the following causes memory leak, View is not released
//# Would it help to set currentTiltElement= null in the last method?
//# No but the following does the job: "currentTiltElement = new Button();"
//# place this in RevertPrepareControlForTilt(FrameworkElement element)
//
currentTiltElement = element;
//
//###################

currentTiltElementCenter = centerPoint;
PrepareTiltReturnStoryboard(element);

ApplyTiltEffect(currentTiltElement, touchPoint, currentTiltElementCenter);
}

Work around:

private static void RevertPrepareControlForTilt(FrameworkElement element)
{
// Debug.WriteLine("Microsoft.Phone.Controls.TiltEffect(), RevertPrepareControlForTilt, ManipulationDelta-= element==>" + element.Name);

element.ManipulationDelta -= TiltEffect_ManipulationDelta;

element.ManipulationCompleted -= TiltEffect_ManipulationCompleted;

element.Projection = null;
element.RenderTransform = null;

CacheMode original;
if (_originalCacheMode.TryGetValue(element, out original))
{
element.CacheMode = original;
_originalCacheMode.Remove(element);
}
else
{
element.CacheMode = null;
}

//###################
//# RdB - Rob de Beir
//# Added the following line to prevent memory leak
//# The view framework element is hold by the static currentTiltElement
//# so by reassigning currentTiltElement, the view framework element is released
currentTiltElement = new Button();
//###################

}


Viewing all articles
Browse latest Browse all 801

Trending Articles