Jump to content
  • Advertisement
Sign in to follow this  
MButchers

[.net] Memory Woes

This topic is 4479 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry for the obscure title, but obscure problems deserve obscure titles! Anyway onto the problem, I have created an ASP.NET web application with a .NET web service embedded within the application, everything runs fine until a call is made into the web service (this is called from the client using javascript to retrieve data to populate a word document), once this is done every page navigation results in an increase in memory usage (typically about 2mb per navigation) for the ASP.NET worker process and as a result it is running out of memory. The WebMethod has EnableSession=true and stores a dataset within the session, however this is removed using the following code so cannot possibly be causing the issue

private void ClearOutput(System.Web.SessionState.HttpSessionState session)
{
	DataSet ds = session["OutputData"] as DataSet;

	if (ds != null)
	{
		ds.Clear();
		ds.Dispose();
		ds = null;

		session.Remove("OutputData");

		GC.Collect();
	}
}

Does anyone have any ideas as to what may be causing this issue? Im wracking my brains but cannot think why the webservice calls should result in this behaviour. Thanks in advance Mark

Share this post


Link to post
Share on other sites
Advertisement
How are you populating the word document? My first guess is you aren't disposing those objects.

Share this post


Link to post
Share on other sites
If you're accessing the Word document through the Word COM automation model, you might try calling Marshal.ReleaseComObject on the reference when you're done with it.

Share this post


Link to post
Share on other sites
Quote:
Original post by MButchers
Sorry for the obscure title, but obscure problems deserve obscure titles!

Just to be contrary, no, obscure problems need clear descriptive titles, so that those who might know about the problem are informed it deals with a topic they know, and which they might be able to help with.

Share this post


Link to post
Share on other sites
Thanks for the replys folks,

The Word application is being instanciated from the Client's browser using javascript so dont have any memory issues with this, the memory is going mad on the server!!

Quote:


Try using just session.Abandon(). It might solve your problem



Unfortunately I have other objects contained within the session which are needed within the application so this is not possible, however sessions do seem to be being abandoned by ASP.NET automatically as it runs out of memory!

Quote:


Quote:Original post by MButchers
Sorry for the obscure title, but obscure problems deserve obscure titles!

Just to be contrary, no, obscure problems need clear descriptive titles, so that those who might know about the problem are informed it deals with a topic they know, and which they might be able to help with.



See your point :)

Am going to look into moving the WebService into its own process, this should at least isolate it from the main application and stop the main app from crashing !!

Many Thanks

Mark

Share this post


Link to post
Share on other sites
I had a similar problem with some billing code I wrote at work; objects were instantiated and disposing them followed by a GC.Collect() call didn't free them immediately. GC.Collect() doesn't actually force .NET to remove objects, it asks it to remove objects it was planning on removing anyway. In my case, the solution turned out to be the using keyword:
using (DataSet ds = Db.FillDataSet(sql)) {
// do stuff
}

This has proved to be the most reliable way to make DataSets go away. I've not done much serious low-level tracing, but I have noticed that they tend to take a while to vanish even if you throw clearance commands at them.

Storing the DataSet in Session makes that impossible, and may well be the root cause of your problems. Do you have to store the DataSet in session? How much data do you have overall - could you keep one dataset as a lazy static property, and retrieve filtered versions of it when needed (and only store user identity in session)? You could also look into storing data in System.Cache with low priorities, and re-fetch it if it isn't available. System.Cache does a great job of cleaning itself up and keeping RAM usage vaguely sane.

As an aside, there is something funky with some of the earlier versions of Atlas. In one project, a javascript->WebServices call through the Atlas framework caused our aspnet worker to keep growing for no apparent reason. This seems to have been resolved in more recent releases, although we mostly use AJAX.NET Pro now (it's faster for data transfer, but doesn't provide any sort of help with UI elements).

Share this post


Link to post
Share on other sites
Cheers Bracket for the input,

will take a look at using the Cache as its a possiblility, the amount of data stored in the service varies, in this case it is to populate about 600 bookmarks in the word document.

It may be possible for me to restructure the web-service to return the whole dataset to the client however this may cause a loss of speed!


Personally I am trying to avoid using ATLAS and am writing my own web-service/javascript interaction functions, as they seem to be a lot faster and are easier to tune to application specific tasks :)

Mark

Share this post


Link to post
Share on other sites
Moving the ASMX web service pages out of the body of the main application and calling a Session.Abandon() on the final call to the service has fixed the problem.

Cheers for all the help guys

Mark

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!