Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Do I need to use GC.Collect? If yes, where?

Reply
Thread Tools

Do I need to use GC.Collect? If yes, where?

 
 
Antonio
Guest
Posts: n/a
 
      07-25-2005
Hello, here is what I am doing.

1) user accesses web page and clicks button to build report
2) web page accesses web service whose data type is DataSet
(public DataSet methodname()...)
3) web service connects to SqlServer, runs BIG report
4) data is returned to web service, web service returns DataSet to web
front-end
5) web front-end prompts user to save Excel file which contains the
DataSet data

While #3 is running, the aspnet_ws.exe process on the web server grows
big, like 200-500 MB.

The problem is the server doesn't seem to release that memory after the
report is done. A few more report runs and the server starts giving
memory errors.

I have seen people saying use GC.Collect() but where would I put that?

 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      07-25-2005
Antonio,

No, you shouldn't be calling GC.Collect, ^especially^ in an ASP.NET
environment. ASP.NET gets into a nice little groove (in terms of GC's, and
when the pattern of use is consistent) which you don't want to mess with by
running your own GC's.

The errors that you are probably getting are due to the % of memory
ASP.NET is allowed to use before the process is recycled. You would have to
up this value in the web.config file for your application, to let your
ASP.NET process take up more memory.

If your report is returning data that is between 200-500 MB, then you
really need to reconsider the design of the report.

Also, Task Manager is not really suitable for monitoring the memory
consumption of an application. You should be using the performance counters
to determine what is being consumed/released, etc, etc.

In the end, ^don't^ call GC.Collect, as in this case, it isn't going to
do anything for you. Just make sure you dispose of all types that implement
IDisposable, and if your report is really that big, then raise the value of
the allowed memory consumption in the web.config file.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
-


"Antonio" <> wrote in message
news: oups.com...
> Hello, here is what I am doing.
>
> 1) user accesses web page and clicks button to build report
> 2) web page accesses web service whose data type is DataSet
> (public DataSet methodname()...)
> 3) web service connects to SqlServer, runs BIG report
> 4) data is returned to web service, web service returns DataSet to web
> front-end
> 5) web front-end prompts user to save Excel file which contains the
> DataSet data
>
> While #3 is running, the aspnet_ws.exe process on the web server grows
> big, like 200-500 MB.
>
> The problem is the server doesn't seem to release that memory after the
> report is done. A few more report runs and the server starts giving
> memory errors.
>
> I have seen people saying use GC.Collect() but where would I put that?
>



 
Reply With Quote
 
 
 
 
Vagabond Software
Guest
Posts: n/a
 
      07-25-2005
"Antonio" <> wrote in message
news: oups.com...
> Hello, here is what I am doing.
>
> 1) user accesses web page and clicks button to build report
> 2) web page accesses web service whose data type is DataSet
> (public DataSet methodname()...)
> 3) web service connects to SqlServer, runs BIG report
> 4) data is returned to web service, web service returns DataSet to web
> front-end
> 5) web front-end prompts user to save Excel file which contains the
> DataSet data
>
> While #3 is running, the aspnet_ws.exe process on the web server grows
> big, like 200-500 MB.
>
> The problem is the server doesn't seem to release that memory after the
> report is done. A few more report runs and the server starts giving
> memory errors.
>
> I have seen people saying use GC.Collect() but where would I put that?


You would probably add a GC.Collect after you call Dispose on the object.
However, I wonder if that is the problem? Is your 200-500 MB data a group
of unmanaged Excel objects? If so, are you sure you're releasing ALL of the
objects?

Carl


 
Reply With Quote
 
Antonio
Guest
Posts: n/a
 
      07-25-2005
ok so don't call GC.Collect(). I have added .Dispose to the datagrids
and datasets. The actual excel file downloaded is usually between 5
and 25 MB. I am not really sure why the process grows by 200 or more
MB. What performance counters would you suggest I watch in perfmon?

thank you Nicholas

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      07-25-2005
The question is not how big is the excel file, the question is how big is
the dataset.
And what datagrids are you talking about? This is a webservice, what are the
datagrids used for?

Willy.

"Antonio" <> wrote in message
news: oups.com...
> ok so don't call GC.Collect(). I have added .Dispose to the datagrids
> and datasets. The actual excel file downloaded is usually between 5
> and 25 MB. I am not really sure why the process grows by 200 or more
> MB. What performance counters would you suggest I watch in perfmon?
>
> thank you Nicholas
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      07-25-2005
Antonio,

It depends on what you want to see. If you run perfmon (from the run
dialog box), you will see a gazillion (ok, almost) entries for performance
counters. You can see things such as number of collections, memory
allocated, etc, etc. They are pretty self-describing, and can give you a
plethora of information.

Also, when working with the Excel sheet, you should make sure that you
call the static ReleaseComObject on the Marshal class to correctly release
the COM objects produced by it (it can leave references lying around).

--
- Nicholas Paldino [.NET/C# MVP]
-

"Antonio" <> wrote in message
news: oups.com...
> ok so don't call GC.Collect(). I have added .Dispose to the datagrids
> and datasets. The actual excel file downloaded is usually between 5
> and 25 MB. I am not really sure why the process grows by 200 or more
> MB. What performance counters would you suggest I watch in perfmon?
>
> thank you Nicholas
>



 
Reply With Quote
 
Antonio
Guest
Posts: n/a
 
      07-26-2005
The datagrid is to get the excel output. See below. I found this in
the asp.net ng. I call the web service which returns the dataset, then
I pass the dataset into this static method (I made it a static method
so all of my web pages can call it.

public static void ExportExcel(System.Data.DataSet ds, int TableIndex,
string FileNameNoExtension, System.Web.HttpResponse response) {
response.Clear();
response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("content-disposition", "attachment;filename=" +
FileNameNoExtension + ".xls");
System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new
System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.DataGrid dg = new
System.Web.UI.WebControls.DataGrid();
dg.DataSource = ds.Tables[TableIndex];
dg.DataBind();
dg.RenderControl(htmlWrite);
response.Write(stringWrite.ToString());
response.End();
ds.Dispose();
}

 
Reply With Quote
 
John Murray
Guest
Posts: n/a
 
      07-26-2005
Are you releasing your Excel references with Marshal.ReleaseCOMObject,
or just setting them to null?

http://support.microsoft.com/default...;EN-US;Q317109

Please note that this is one of the cases where MS actually does
reference manually calling GC.Collect ... although it's sort of a hack
to deal with reference counting problems in the RCW.



Antonio wrote:
> Hello, here is what I am doing.
>
> 1) user accesses web page and clicks button to build report
> 2) web page accesses web service whose data type is DataSet
> (public DataSet methodname()...)
> 3) web service connects to SqlServer, runs BIG report
> 4) data is returned to web service, web service returns DataSet to web
> front-end
> 5) web front-end prompts user to save Excel file which contains the
> DataSet data
>
> While #3 is running, the aspnet_ws.exe process on the web server grows
> big, like 200-500 MB.
>
> The problem is the server doesn't seem to release that memory after the
> report is done. A few more report runs and the server starts giving
> memory errors.
>
> I have seen people saying use GC.Collect() but where would I put that?
>

 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      07-26-2005

"Antonio" <> wrote in message
news: oups.com...
> The datagrid is to get the excel output. See below. I found this in
> the asp.net ng. I call the web service which returns the dataset, then
> I pass the dataset into this static method (I made it a static method
> so all of my web pages can call it.
>
> public static void ExportExcel(System.Data.DataSet ds, int TableIndex,
> string FileNameNoExtension, System.Web.HttpResponse response) {
> response.Clear();
> response.Charset = "";
> response.ContentType = "application/vnd.ms-excel";
> response.AddHeader("content-disposition", "attachment;filename=" +
> FileNameNoExtension + ".xls");
> System.IO.StringWriter stringWrite = new System.IO.StringWriter();
> System.Web.UI.HtmlTextWriter htmlWrite = new
> System.Web.UI.HtmlTextWriter(stringWrite);
> System.Web.UI.WebControls.DataGrid dg = new
> System.Web.UI.WebControls.DataGrid();
> dg.DataSource = ds.Tables[TableIndex];
> dg.DataBind();
> dg.RenderControl(htmlWrite);
> response.Write(stringWrite.ToString());
> response.End();
> ds.Dispose();
> }
>


Ok, if I understand you correctly, you have following logical tiers:

1. browser client
2. a web application (asp.net)
3. a web service
4. a SQL DB

How about the physical tiers, do 2 and 3 run on the same server (not really
a server, if I'm not mistaken you run this on XP)?
Who's producing the Excel output? And what's the relation between this and
the DS generated by the report?

How large is the dataset passed from the WS to the WA, this is important as
if both run in the same process (aspnet_wp.exe) the working set will contain
two instances of the same DS at some point in time.


Willy.



 
Reply With Quote
 
Antonio
Guest
Posts: n/a
 
      07-26-2005
Yes!

The server are Windows Server 2000 SP4. 2 and 3 DO run on the same
server! #2 is producing the excel file. #3 only connects to the
database and returns to #2 the dataset. then the dataset is handed to
the static method that productces the excel file.

I do not know how big the dataset is but I will try to look.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
How do I know when to use the Viewstate and when to use the posted data? :-) Simon ASP .Net 1 11-09-2004 02:32 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57