none
Performance Issue RRS feed

  • Question

  • Hii,

    I am developing an application which runs in background continuously. The application performs some task(takes around 3 seconds) every minute.

    The application is only active for the first 3 seconds but needs to run every minute, because of this it keeps a lot of RAM reserved, which is not required except for the first few seconds of every minute.

    I need to minimize the usage of RAM. To achieve this I have created two projects:

    1. First projects performs the task that i need and kills itself, which takes around 3 seconds.
    2. Second projects runs continuously in background and calls the .exe file of 1St project every minute.

    This way I am able to minimize my RAM usage to 33% of initial value.

    I would like to know if this approach is optimum or is there a better approach for solving this issue?

    Thanks in advance.


    • Edited by Naverse Wednesday, April 20, 2011 2:50 PM
    Wednesday, April 20, 2011 12:11 PM

Answers

  • I suggest recreating all your Var objects (at the very least the IDisposable ones) every time you run this task, and then when you are done, calling Dispose(), and setting your objects to null at the end of your task. This should clean up memory between runs.
    • Marked as answer by Naverse Wednesday, April 20, 2011 2:02 PM
    Wednesday, April 20, 2011 1:07 PM

All replies

  • hi,

    while it may have no effect: have you forced a garbage collection at the task end?

    http://msdn.microsoft.com/en-us/library/xe0c2357.aspx


    Microsoft MVP Office Access
    https://mvp.support.microsoft.com/profile/Stefan.Hoffmann
    • Marked as answer by Naverse Wednesday, April 20, 2011 2:02 PM
    • Unmarked as answer by Naverse Wednesday, April 20, 2011 2:51 PM
    Wednesday, April 20, 2011 12:22 PM
  • Your solution sounds clever, but if your app keeps a lot of RAM sitting around, using it every once in a while, that is often a sign of a bad design. It could be that a large list of objects or other memory hog is not going out of scope. If you would post a code sample, smeone may be able to find the memory hog.

    Remember, debugging is twice as hard as writing the code in the first place, so if you write code as cleverly as possible, you are by definition unable to debug it.

    Wednesday, April 20, 2011 12:27 PM
  • Hello kendfrey, you can make your main classes IDisposable (do stuff inside using) and to achive a run every minute you can use:

    System.Threading.ThreadPool.RegisterWaitForSingleObject
    

    Hope this helps,

    Miguel.

    Wednesday, April 20, 2011 12:35 PM
  • Perhaps you meant to be talking to the OP? I am not having this problem.
    Wednesday, April 20, 2011 12:41 PM
  • Nope I didn't use the garbage collection method but I dispose most of the objects.

    Thanks for the suggestion I'll look into it.


    Wednesday, April 20, 2011 12:46 PM
  • Mainly I am using two static functions defined in two separate classes(main class and GetXML).

    I have created another abstract class "Var" which contains static variables which i access and modify from these two static functions.

    The function call is :  GetXML.getConfig(3); drawText();

     

    //the draw text function//

    public static void drawText(){

                Var.fontColor = Color.FromArgb(Var.fontOpacity, Var.fontColor);

                Var.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAliasGridFit;

                Var.g.DrawString(Var.caption, new Font(Var.font, Var.fontSize), new SolidBrush(Var.fontColor), Var.rect, Var.strFormat);

            }

    //the GetXML.getConfig() function//

    public static void getConfig(int i){

                try{

                    Var.xmlDoc.Load("Resources\\XMLs\\tempalte.xml");

                    XmlElement elem = Var.xmlDoc.GetElementById(i.ToString());

                    if(elem!=null){

                        Var.enable=Boolean.Parse(elem.GetElementsByTagName("enable")[0].InnerText);

                        Var.location = elem.GetElementsByTagName("location")[0].InnerText;

                        Var.caption = elem.GetElementsByTagName("caption")[0].InnerText;

                        Var.font = elem.GetElementsByTagName("font")[0].InnerText;

                        Var.fontColor = System.Drawing.ColorTranslator.FromHtml(elem.GetElementsByTagName("fontColor")[0].InnerText);

                        Var.fontOpacity = Convert.ToByte(elem.GetElementsByTagName("fontOpacity")[0].InnerText);

                        Var.fontSize = Convert.ToInt16(elem.GetElementsByTagName("fontSize")[0].InnerText)*Var.isr;

    }

                }catch{}

            }

    Wednesday, April 20, 2011 12:58 PM
  • I suggest recreating all your Var objects (at the very least the IDisposable ones) every time you run this task, and then when you are done, calling Dispose(), and setting your objects to null at the end of your task. This should clean up memory between runs.
    • Marked as answer by Naverse Wednesday, April 20, 2011 2:02 PM
    Wednesday, April 20, 2011 1:07 PM