Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Fuite Mémoire

2 réponses
Avatar
Mickael \(VFI\)
Bonjour,

J'ai un problème de fuite de mémoire très important.
Apparemment c'est l'utilisation de INotifyPropertyChanged qui pose problème
(Voir code ci-dessous)

Quelqu'un à une solution pour résoudre ce problème?


Merci


Imports
System.ComponentModel

Public Class Form1
Private ExitLoop As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Label1.Text = "Started"

ExitLoop = False
Do While Not ExitLoop
Dim a1 As Demo = New Demo
Application.DoEvents()
Loop

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click, Me.FormClosing
ExitLoop = True
End Sub
End Class

PublicClass Demo
Implements INotifyPropertyChanged
Private mchaine AsString = String.Empty
PublicEvent PropertyChanged As PropertyChangedEventHandler Implements
INotifyPropertyChanged.PropertyChanged

PrivateSub NotifyPropertyChanged(ByVal info AsString)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
EndSub

PublicProperty chaine() AsString
Get
ReturnMe.mchaine
EndGet
Set(ByVal value AsString)
IfNot (value = mchaine) Then
Me.mchaine = value
NotifyPropertyChanged("chaine")
EndIf
EndSet
EndProperty
EndClass

2 réponses

Avatar
Gilles TOURREAU [MVP]
"Mickael (VFI)" a écrit dans le message de
news:

Bonjour,

J'ai un problème de fuite de mémoire très important.
Apparemment c'est l'utilisation de INotifyPropertyChanged qui pose
problème (Voir code ci-dessous)

Quelqu'un à une solution pour résoudre ce problème?


Merci


Imports
System.ComponentModel

Public Class Form1
Private ExitLoop As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Label1.Text = "Started"

ExitLoop = False
Do While Not ExitLoop
Dim a1 As Demo = New Demo
Application.DoEvents()
Loop

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click, Me.FormClosing
ExitLoop = True
End Sub
End Class

PublicClass Demo
Implements INotifyPropertyChanged
Private mchaine AsString = String.Empty
PublicEvent PropertyChanged As PropertyChangedEventHandler Implements
INotifyPropertyChanged.PropertyChanged

PrivateSub NotifyPropertyChanged(ByVal info AsString)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
EndSub

PublicProperty chaine() AsString
Get
ReturnMe.mchaine
EndGet
Set(ByVal value AsString)
IfNot (value = mchaine) Then
Me.mchaine = value
NotifyPropertyChanged("chaine")
EndIf
EndSet
EndProperty
EndClass




Bonjour,

Sous .NET la notion de fuite mémoire n'existe pas. Ce problème de libération
est automatiquement géré par une femme de ménage appelée Jessy (GC).

Cordialement

--
Gilles TOURREAU - MVP C#


S.A.R.L. P.O.S
Le spécialiste en motoculture depuis + de 30 ans !
http://www.pos.fr
Avatar
Patrice
Création répetée d'objets plutôt que fuite mémoire ? Si c'est pour une démo
de fonctionnement de INotifyPropertychanged je ne vois pas pourquoi on crée
de nouveaux objects a1 apparemment inutilisé tant que l'utilisateur n'appuie
pas sur un autre bouton ce qui peut aller très très vite...


--
Patrice


"Mickael (VFI)" a écrit dans le message de
groupe de discussion :

Bonjour,

J'ai un problème de fuite de mémoire très important.
Apparemment c'est l'utilisation de INotifyPropertyChanged qui pose
problème (Voir code ci-dessous)

Quelqu'un à une solution pour résoudre ce problème?


Merci


Imports
System.ComponentModel

Public Class Form1
Private ExitLoop As Boolean = False
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Me.Label1.Text = "Started"

ExitLoop = False
Do While Not ExitLoop
Dim a1 As Demo = New Demo
Application.DoEvents()
Loop

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click, Me.FormClosing
ExitLoop = True
End Sub
End Class

PublicClass Demo
Implements INotifyPropertyChanged
Private mchaine AsString = String.Empty
PublicEvent PropertyChanged As PropertyChangedEventHandler Implements
INotifyPropertyChanged.PropertyChanged

PrivateSub NotifyPropertyChanged(ByVal info AsString)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
EndSub

PublicProperty chaine() AsString
Get
ReturnMe.mchaine
EndGet
Set(ByVal value AsString)
IfNot (value = mchaine) Then
Me.mchaine = value
NotifyPropertyChanged("chaine")
EndIf
EndSet
EndProperty
EndClass