C# Windows Phone 8中的谷歌广告内存泄漏
我对WP8中GoogleAdMob的性能有很多问题,所以现在我写了一个简单的项目来测试。我只有2页的用户控件“”包含admob 我的scerano在主页和第二页之间重复导航,都使用应用程序中的按钮或硬件后退键 我的应用程序开始时使用了40Mb内存。我试图为用户控件实现IDispose,并在每次导航后清除导航历史记录,但内存堆增长非常快,我的应用程序在20多次导航后崩溃。如果我停止导航,我注意到一分钟后内存确实减少了,但并没有减少多少(例如从140下降到120)。所以现在我不知道如何避免这个问题 这是MainPage.xaml(与第二页相同): 这是GoogleAds用户控件(使用默认xaml,我不在这里发布)C# Windows Phone 8中的谷歌广告内存泄漏,c#,xaml,windows-phone-8,admob,C#,Xaml,Windows Phone 8,Admob,我对WP8中GoogleAdMob的性能有很多问题,所以现在我写了一个简单的项目来测试。我只有2页的用户控件“”包含admob 我的scerano在主页和第二页之间重复导航,都使用应用程序中的按钮或硬件后退键 我的应用程序开始时使用了40Mb内存。我试图为用户控件实现IDispose,并在每次导航后清除导航历史记录,但内存堆增长非常快,我的应用程序在20多次导航后崩溃。如果我停止导航,我注意到一分钟后内存确实减少了,但并没有减少多少(例如从140下降到120)。所以现在我不知道如何避免这个问题
试着把收集到的黏糊糊不是用空的,而是用空的onnavigatingfrom@jackjop我不确定有什么不同?我不知道,但有一种可能性,页面从未卸载,或者在页面卸载后,Googleds可能无法处理。一切都可以在wp中发生。我觉得还是不稳定你找到解决办法了吗?
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<-- a control from coding4fun to show memory couter directy in screen-->
<coding4fun:MemoryCounter/>
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}" Margin="12,0"/>
<TextBlock Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="SecondPage" Width="200" Height="100"
Click="Button_Click"/>
<test:GoogleAds x:Name="googletest" VerticalAlignment="Bottom" Height="60"/>
</Grid>
</Grid>
public partial class MainPage : PhoneApplicationPage
{
// Constructor
public MainPage()
{
InitializeComponent();
this.Unloaded += MainPage_Unloaded;
}
void MainPage_Unloaded(object sender, RoutedEventArgs e)
{
Debug.WriteLine("unload mainpage");
googletest.Dispose();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/SecondPage.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
if (NavigationService.CanGoBack || NavigationService.CanGoForward)
while (NavigationService.BackStack.Count() > 0)
{
Debug.WriteLine("remove backentry");
NavigationService.RemoveBackEntry();
}
}
}
public partial class GoogleAds : UserControl, IDisposable
{
public GoogleAds()
{
InitializeComponent();
LoadAd();
}
AdView ad;
AdRequest request;
void LoadAd()
{
ad = new AdView()
{
AdUnitID = "test-key",
Format = AdFormats.Banner
};
request = new AdRequest();
request.ForceTesting = true;
ad.ReceivedAd += ad_ReceivedAd;
ad.FailedToReceiveAd += ad_FailedToReceiveAd;
LayoutRoot.Children.Add(ad);
ad.LoadAd(request);
}
void ad_FailedToReceiveAd(object sender, AdErrorEventArgs e)
{
Debug.WriteLine("fail ad");
}
void ad_ReceivedAd(object sender, AdEventArgs e)
{
Debug.WriteLine("success ad");
}
//
bool disposed = false;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposed)
return;
if (disposing)
{
}
if (ad != null)
{
ad.ReceivedAd -= ad_ReceivedAd;
ad.FailedToReceiveAd -= ad_FailedToReceiveAd;
ad = null;
}
disposed = true;
Debug.WriteLine("dispose googleads");
}
~GoogleAds()
{
Dispose(false);
}
}