0

this is the first form known as a login when I switched from login to registration then registration to log in the memory keep increasing it won't stop how can I resolve this?

Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        Me.Hide()
        Dim registration As New Registration()
        registration.Show()
        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()

        Close()
    End Sub

the second form is known as registration

  Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles linkLabel1.LinkClicked
        Me.Hide()
        Dim login As New Login()
        login.Show()
        GC.Collect()
        GC.WaitForPendingFinalizers()
        GC.Collect()
        Close()
    End Sub

I'm using materialskin and a panel with image on each form and garbage collector won't work and the close() looks like it didnt work

enter image description here

1 Answers1

0

fixed it here's the code on login form

Imports MaterialSkin.Controls

Public Class Login
    Inherits MaterialForm
   Private _registration As Registration

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub frm2_FormClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
        _registration = Nothing 'If form is closed make sure reference is set to null
        _registration.Show()
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles LinkLabel1.LinkClicked
        If _registration Is Nothing Then
            _registration = New Registration() 'Create form if not created
            AddHandler _registration.FormClosed, AddressOf frm2_FormClosed 'Add eventhandler to cleanup after form closes
        End If

        _registration.Show(Me) 'Show Form assigning this form as the forms owner
        Hide()
    End Sub

registration form

Imports MaterialSkin.Controls

Public Class Registration
    Inherits MaterialForm
 Public Sub New()

        InitializeComponent()
    End Sub

    Private Sub LinkLabel1_LinkClicked(sender As Object, e As LinkLabelLinkClickedEventArgs) Handles linkLabel1.LinkClicked
        Owner.Show()
        Hide()
    End Sub