[SL3] Problème avec le garbage collector
Salut à tous ;)
Aujourd'hui j'ai un gros soucis ... pour des soucis de performance je dois détruire des objets à certains moment, malheureusement le GC (Garbage Collector) ne fais pas bien son taf. Il nettoie quand il veut même si je le force il ne le fait pas tout de suite.
Du coup j'ai fait un petit projet de test pour bien comprendre se qui se passe, j'ai un objet tout simple et un bouton, quand je clic sur mon bouton ca détruit l'objet.
Sauf que si je met un point d'arrêt dans le destructeur, je m'arrête que lors du deuxième clic voir des fois plus, comment faire pour que je passe dedans du 1er coup ??
Voici mon "Main Page.xaml" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| <UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:SilverlightDisposeTest" x:Class="SilverlightDisposeTest.MainPage"
>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<local:ucCell x:Name="ucTest"/>
<Button Content="Test Me" Grid.Row="1" Click="Button_Click"/>
</Grid>
</UserControl> |
Le "main Page.xaml.cs" :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightDisposeTest
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
this.LayoutRoot.Children.Remove(ucTest);
ucTest = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
} |
et mon objet ucCell :
le xaml :
Code:
1 2 3 4 5 6 7
| <UserControl x:Class="SilverlightDisposeTest.ucCell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid x:Name="LayoutRoot" Background="White">
<Button x:Name="btnTest" Content="Test"></Button>
</Grid>
</UserControl> |
et le c# :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace SilverlightDisposeTest
{
public partial class ucCell : UserControl,IDisposable
{
public ucCell()
{
InitializeComponent();
}
~ucCell()
{
Dispose();
}
#region IDisposable Membres
public void Dispose()
{
}
#endregion
}
} |
merci de votre aide