Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Joey - 03 Aug 2007 20:13 GMT
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
Peter Bromberg [C# MVP] - 03 Aug 2007 21:54 GMT
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

> VS2005
> asp.net 2.0
[quoted text clipped - 32 lines]
>
> JP
Joey - 06 Aug 2007 14:21 GMT
On Aug 3, 3:54 pm, Peter Bromberg [C# MVP]
<pbromb...@yahoo.yohohhoandabottleofrum.com> 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:
[quoted text clipped - 46 lines]
>
> - 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 - 06 Aug 2007 17:53 GMT
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.

> On Aug 3, 3:54 pm, Peter Bromberg [C# MVP]
> <pbromb...@yahoo.yohohhoandabottleofrum.com> wrote:
[quoted text clipped - 52 lines]
> That will require a lot of recoding! Does anyone know of a way to
> "destroy" the variables/free the memory with code?
Joey - 06 Aug 2007 18:05 GMT
> 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 - 06 Aug 2007 18:07 GMT
> > Static variable should not be a problem. Although if you are using it on a
> > Page level then you most likely doing something wrong.
[quoted text clipped - 4 lines]
> 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 - 06 Aug 2007 18:29 GMT
You got it.
Think of static variables as of "global variables"

George

>> > Static variable should not be a problem. Although if you are using it
>> > on a
[quoted text clipped - 9 lines]
> Okay Okay I think I get it. Since they are static, they are not
> instantiated in the first place! Right?
Mark Rae [MVP] - 06 Aug 2007 18:35 GMT
> Think of static variables as of "global variables"

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

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.