Help: Memory Management For My asp.net Managed Code!

Discussion in 'ASP .Net' started by Joey, Aug 3, 2007.

  1. Joey

    Joey Guest

    VS2005
    asp.net 2.0
    C#
    Developing with File System/Cassini instead of IIS (publish to IIS
    every so often)

    Hello guys,

    I have a web app where I am using static variables on many pages to
    maintain values between postbacks. I am also using several static
    properties and methods on a class within my custom libraries (a .cs
    file in the App_Code folder).

    After constantly running the app while debugging (sometimes for three
    or four hours straight,) my machine begins to slow to a crawl. I
    ultimately receive a "System out of memory" message. The only program
    being run on this machine during this time is Visual Studio 2005 w/my
    web site (via the green triangle "Start Debugging" button) in the VS
    IDE.

    There is obviously some problem going on with memory management here.
    Apparently I still need to destruct/destroy some objects manually,
    since the .net garbage collector is not getting it.

    Questions:

    What am I doing wrong here?

    How do I free the memory?

    When I publish the site and run OUT of debug mode with IIS on the web
    server, will it make any difference?

    TIA

    JP
     
    Joey, Aug 3, 2007
    #1
    1. Advertising

  2. The solution is very simple: *do not* use static fields in a Page class to
    attempt to maintain values between postbacks. Your alternatives are:
    1) ViewState
    2) Session
    3) Hidden Form Fields
    4) Cache
    -- Peter
    Recursion: see Recursion
    site: http://www.eggheadcafe.com
    unBlog: http://petesbloggerama.blogspot.com
    bogMetaFinder: http://www.blogmetafinder.com



    "Joey" wrote:

    > VS2005
    > asp.net 2.0
    > C#
    > Developing with File System/Cassini instead of IIS (publish to IIS
    > every so often)
    >
    > Hello guys,
    >
    > I have a web app where I am using static variables on many pages to
    > maintain values between postbacks. I am also using several static
    > properties and methods on a class within my custom libraries (a .cs
    > file in the App_Code folder).
    >
    > After constantly running the app while debugging (sometimes for three
    > or four hours straight,) my machine begins to slow to a crawl. I
    > ultimately receive a "System out of memory" message. The only program
    > being run on this machine during this time is Visual Studio 2005 w/my
    > web site (via the green triangle "Start Debugging" button) in the VS
    > IDE.
    >
    > There is obviously some problem going on with memory management here.
    > Apparently I still need to destruct/destroy some objects manually,
    > since the .net garbage collector is not getting it.
    >
    > Questions:
    >
    > What am I doing wrong here?
    >
    > How do I free the memory?
    >
    > When I publish the site and run OUT of debug mode with IIS on the web
    > server, will it make any difference?
    >
    > TIA
    >
    > JP
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Aug 3, 2007
    #2
    1. Advertising

  3. Joey

    Joey Guest

    On Aug 3, 3:54 pm, Peter Bromberg [C# MVP]
    <> wrote:
    > The solution is very simple: *do not* use static fields in a Page class to
    > attempt to maintain values between postbacks. Your alternatives are:
    > 1) ViewState
    > 2) Session
    > 3) Hidden Form Fields
    > 4) Cache
    > -- Peter
    > Recursion: see Recursion
    > site: http://www.eggheadcafe.com
    > unBlog: http://petesbloggerama.blogspot.com
    > bogMetaFinder: http://www.blogmetafinder.com
    >
    >
    >
    > "Joey" wrote:
    > > VS2005
    > > asp.net 2.0
    > > C#
    > > Developing with File System/Cassini instead of IIS (publish to IIS
    > > every so often)

    >
    > > Hello guys,

    >
    > > I have a web app where I am using static variables on many pages to
    > > maintain values between postbacks. I am also using several static
    > > properties and methods on a class within my custom libraries (a .cs
    > > file in the App_Code folder).

    >
    > > After constantly running the app while debugging (sometimes for three
    > > or four hours straight,) my machine begins to slow to a crawl. I
    > > ultimately receive a "System out of memory" message. The only program
    > > being run on this machine during this time is Visual Studio 2005 w/my
    > > web site (via the green triangle "Start Debugging" button) in the VS
    > > IDE.

    >
    > > There is obviously some problem going on with memory management here.
    > > Apparently I still need to destruct/destroy some objects manually,
    > > since the .net garbage collector is not getting it.

    >
    > > Questions:

    >
    > > What am I doing wrong here?

    >
    > > How do I free the memory?

    >
    > > When I publish the site and run OUT of debug mode with IIS on the web
    > > server, will it make any difference?

    >
    > > TIA

    >
    > > JP- Hide quoted text -

    >
    > - Show quoted text -


    That will require a lot of recoding! Does anyone know of a way to
    "destroy" the variables/free the memory with code?
     
    Joey, Aug 6, 2007
    #3
  4. Static variable should not be a problem. Although if you are using it on a
    Page level then you most likely doing something wrong.
    All users of the site will share that variable. So you can not use them to
    maintain values between postbacks. Read up on "static" in C#.
    -----------------------------------------------------------
    Do you use a COM objects in your project? Like may be you doing MS Office
    automation?
    That can easily lead to memory leaks (without proper coding)

    George.




    "Joey" <> wrote in message
    news:...
    > On Aug 3, 3:54 pm, Peter Bromberg [C# MVP]
    > <> wrote:
    >> The solution is very simple: *do not* use static fields in a Page class
    >> to
    >> attempt to maintain values between postbacks. Your alternatives are:
    >> 1) ViewState
    >> 2) Session
    >> 3) Hidden Form Fields
    >> 4) Cache
    >> -- Peter
    >> Recursion: see Recursion
    >> site: http://www.eggheadcafe.com
    >> unBlog: http://petesbloggerama.blogspot.com
    >> bogMetaFinder: http://www.blogmetafinder.com
    >>
    >>
    >>
    >> "Joey" wrote:
    >> > VS2005
    >> > asp.net 2.0
    >> > C#
    >> > Developing with File System/Cassini instead of IIS (publish to IIS
    >> > every so often)

    >>
    >> > Hello guys,

    >>
    >> > I have a web app where I am using static variables on many pages to
    >> > maintain values between postbacks. I am also using several static
    >> > properties and methods on a class within my custom libraries (a .cs
    >> > file in the App_Code folder).

    >>
    >> > After constantly running the app while debugging (sometimes for three
    >> > or four hours straight,) my machine begins to slow to a crawl. I
    >> > ultimately receive a "System out of memory" message. The only program
    >> > being run on this machine during this time is Visual Studio 2005 w/my
    >> > web site (via the green triangle "Start Debugging" button) in the VS
    >> > IDE.

    >>
    >> > There is obviously some problem going on with memory management here.
    >> > Apparently I still need to destruct/destroy some objects manually,
    >> > since the .net garbage collector is not getting it.

    >>
    >> > Questions:

    >>
    >> > What am I doing wrong here?

    >>
    >> > How do I free the memory?

    >>
    >> > When I publish the site and run OUT of debug mode with IIS on the web
    >> > server, will it make any difference?

    >>
    >> > TIA

    >>
    >> > JP- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    > That will require a lot of recoding! Does anyone know of a way to
    > "destroy" the variables/free the memory with code?
    >
     
    George Ter-Saakov, Aug 6, 2007
    #4
  5. Joey

    Joey Guest

    On Aug 6, 11:53 am, "George Ter-Saakov" <> wrote:
    > Static variable should not be a problem. Although if you are using it on a
    > Page level then you most likely doing something wrong.
    > All users of the site will share that variable. So you can not use them to
    > maintain values between postbacks. Read up on "static" in C#.


    Whoa! The static variables are members of the page class. I thought
    different page objects were being instatiated with each page view. Is
    this not true?
     
    Joey, Aug 6, 2007
    #5
  6. Joey

    Joey Guest

    On Aug 6, 12:05 pm, Joey <> wrote:
    > On Aug 6, 11:53 am, "George Ter-Saakov" <> wrote:
    >
    > > Static variable should not be a problem. Although if you are using it on a
    > > Page level then you most likely doing something wrong.
    > > All users of the site will share that variable. So you can not use them to
    > > maintain values between postbacks. Read up on "static" in C#.

    >
    > Whoa! The static variables are members of the page class. I thought
    > different page objects were being instatiated with each page view. Is
    > this not true?


    Okay Okay I think I get it. Since they are static, they are not
    instantiated in the first place! Right?
     
    Joey, Aug 6, 2007
    #6
  7. You got it.
    Think of static variables as of "global variables"

    George



    "Joey" <> wrote in message
    news:...
    > On Aug 6, 12:05 pm, Joey <> wrote:
    >> On Aug 6, 11:53 am, "George Ter-Saakov" <> wrote:
    >>
    >> > Static variable should not be a problem. Although if you are using it
    >> > on a
    >> > Page level then you most likely doing something wrong.
    >> > All users of the site will share that variable. So you can not use them
    >> > to
    >> > maintain values between postbacks. Read up on "static" in C#.

    >>
    >> Whoa! The static variables are members of the page class. I thought
    >> different page objects were being instatiated with each page view. Is
    >> this not true?

    >
    > Okay Okay I think I get it. Since they are static, they are not
    > instantiated in the first place! Right?
    >
     
    George Ter-Saakov, Aug 6, 2007
    #7
  8. "George Ter-Saakov" <> wrote in message
    news:...

    > Think of static variables as of "global variables"


    Yes indeed. Static variables need *very* careful management in ASP.NET...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Aug 6, 2007
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandru Savescu
    Replies:
    0
    Views:
    372
    Alexandru Savescu
    Jan 7, 2004
  2. draskin
    Replies:
    0
    Views:
    317
    draskin
    Jan 9, 2007
  3. Dave Burns
    Replies:
    2
    Views:
    649
    Dave Burns
    Jan 12, 2007
  4. Dave Burns
    Replies:
    0
    Views:
    399
    Dave Burns
    Jan 12, 2007
  5. Allen Maki
    Replies:
    1
    Views:
    394
    BradM
    May 30, 2007
Loading...

Share This Page