Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 12th, 2008, 01:51 AM
Authorized User
 
Join Date: May 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kalyanykk
Default memory allocation for a dataset

Is class level declaration of a dataset object consumes more memory or declaration of dataset object in each procedure in a class consumes more memory.

For example:
I have declared the below dataset at class level
DataSet dsTest=new DataSet();

Is it the best practice or it is best to define dataset as shown below
DataSet dsTest;

and then initiate the dataset object at procedure level where ever necessary as shown below
dsTest=new DataSet();

Please suggest me which is the best practice to follow, & which consumes more memory.

 
Old August 12th, 2008, 02:07 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

Its not a case of it "consuming more memory" per se, its more about when the memory is freed up..

I would strongly recommend NEVER putting a DataSet at static class level.
If its at [instance] class level, the DataSet will not be destroyed until the instance of the class is..
If its at procedural level, then it is destroyed when it is out of scope within the procedure, for example:
Code:
void SomeMethod()
{
DataSet ds1 = GetDataSet1(); // Code omitted for clarity
if (something)
{
DataSet ds2 = GetDataSet2(); // Code omitted for clarity
// Some more code
} // ds2 will be tagged for GC here
else
 // Something else
}
// Other method code
} // ds1 will be tagged for GC here
Note: I didn't say "destroyed". I always keep in the back of my mind that you cannot guarantee when objects will be destroyed due to the garbage collection model of .NET.

As for "best practice". Always scope things as low as possible. If you only need it within a method, only use it in a method. If you need it higher, then you may need to think about the data access model more. For example. A customer database with 10M records is used across the application, but you wouldnt throw that in a DataSet at application scope, would you? ;)

I hope this helps.

Rob
http://cantgrokwontgrok.blogspot.com
 
Old August 12th, 2008, 02:17 AM
Authorized User
 
Join Date: May 2008
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kalyanykk
Default

Thank you Rob for your valuable information..:)

 
Old August 12th, 2008, 02:24 AM
Friend of Wrox
 
Join Date: Mar 2007
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

No problem, HTH :)

Rob
http://cantgrokwontgrok.blogspot.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting a untyped dataset to a typed dataset daphnean Visual Studio 2005 0 July 13th, 2006 01:16 AM
VBA memory allocation ychou006 Excel VBA 1 December 21st, 2005 01:03 PM
local memory allocation limit ychou006 Excel VBA 1 August 8th, 2005 07:59 AM
Using DataSet in the memory cache?? thomaz C# 3 June 15th, 2004 01:19 PM
Re: SQL Server dataset to ACCESS dataset dazzer ADO.NET 0 March 22nd, 2004 05:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.