Frage

I have some button on my form. When I click on every buttons run new form with same buttons. When I am clicking many times, show error OutOfMemory.
I think this is because I create a lot of form objects.
May be can clear stack or use form from stack if form is there?

War es hilfreich?

Lösung

you need to use the Singleton pattern for your code. In Singleton Pattern, It will create only one object of your Form Class. If the object is null then it will create a new one else , it will return the current one. For this kindly refer to following code.

// Private Constructor

private static myForm thisForm = null;

private myForm()
{
     thisForm = this;
}

// Now to Create Object, you need to create following getInstance Method

public static myForm getInstance()
{
         if ( thisForm == null ) 
         {
                thisForm = new myForm();
         }
         return thisForm;
}

try above logic in your whole code. Your OutOfMemory Problem will 100% get solved.

Andere Tipps

You are keeping pointers (references) to old components which causes a memory leak. Make sure never to store components as members of your class unless you clear them later.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top