Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I basically have a listbox that has postcode areas i.e : AE,CW,GU etc etc.

The user selects this and then a postback occurs - an sql statement is builts and a database query operation is performed and the results are returned to a datatable called tempdata.

So far so good. I then need to loop through this datatable and copy the records to my main viewstate datatable which is the datasource for google maps api.

C#
DataTable tempstore = GetData(querystring, "");

//check tempstore has rows otherwise add defaultcust as default otherwise map will be blank

if (tempstore.Rows.Count == 0)
{
    tempstore = GetData("WHERE CUSTCODE=='CD344'", "");

    infoalert.Visible = true;

    infoalert.InnerHtml = "No Results Returned For Selection";
}

foreach (DataRow row in tempstore.Rows)
{

    dtpc.ImportRow(row);
    

} 
dtpc.AcceptChanges();


So my main datatable can grow and grow as users add more postcodes. However when it gets to around 500 rows or so I get a huge memory spike only on postback and then it settles back down.

My ram usage goes from 2gb to 3gb and if even more postcodes is selected it maxes the memory and crashes my pc.

If I remove the:

dtpc.Importrow(row);
the memory spike goes completely, obviously because the main datatable has no rows. I thought you only run into memory issues when you have thousands of rows?

Any help would be much appreciated.

thank you
Posted
Updated 23-Dec-14 4:22am
v2
Comments
DamithSL 23-Dec-14 9:42am    
what is dtpc? why you need to merge dtpc and tempstore? can't you directly use tempstore as google map data source?
have you try by moving dtpc.AcceptChanges after the loop?
foreach (DataRow row in tempstore.Rows)
{
dtpc.ImportRow(row);
}
dtpc.AcceptChanges();
DHicks19 23-Dec-14 10:16am    
dtpc is the main datasource for google maps. Dtpc is in a viewstate, so the user can use various filters on the webform and these rows then get added to dtpc and are still available after postback.
I moved the acceptchanges outside of the loop and its still spiking the memory around 500 rows or so.

thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900