Real-World ASP.NET 2.0, Datasets, DAL, Dataview, and Disposal

Posted on 2007-11-26
Last Modified: 2013-11-07

I'm rewriting an app, and am starting to worry about long term performance of the way I'm writing it. First, a little background, and please read all of this because I think it all comes into play. Google EE Linkers need not apply.

I'm using Subsonic as my DAL, and subclassing it for the most part. I'm trying to avoid using their collections within the page classes (although sometimes that's just so easy it's sick!), and wrapping things in my own DAL (as seen below).

Getting to my questions,

1.) When I return a DataSet, how is that destroyed? Does the GC come by at the end of the page and wipe all that up? If so, is it something I can rely on, or is it like ASP Classics, "Oh, we close all connections so you don't have to *wink wink*?

2.) Same thing with a DataView, and would it be better to return the dataset and work with that, or is it roughly equivalent

3.) Same thing with SubSonic COLLECTIONS

4.) Any recommendations on making my DAL a little leaner, meaner, and extensible?

Points will be awarded to those who

a.) Link me to PRECISELY what I'm looking for
b.) Engage and really try to understand what I'm trying to accomplish.

I've asked these types of "theory" or best practices questions before, and have been consistently disappointed with the Interaction. I would really like to LEARN here, not just quick fix, and not with people randomly linking me garbage that doesn't really apply (the quick points people).

Thanks in advance.
public class StatusControl
	public static DataView GetAllStatus()
        DataSet ds0 = new DataSet();
        IDataReader i1 = SPs.SelectStatusAll().GetReader();
        ds0.Tables[0].Load(i1, LoadOption.Upsert);
        DataView dvView = ds0.Tables[0].DefaultView;
        return dvView;

Open in new window

Question by:NauticalNonsense
  • 3
  • 2
LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 20353392
1) Garbage collection is non-deterministic--you can't predict when it will run.

2) It is a pretty complex algorithm that takes into account all kinds of things, but doesn't use reference counting.

3) With local variables that aren't passed outside of a method, the reference variables will be automatically garbage collected.

4) If an object implements the IDisposable interface, you can control when the object is destroyed by calling the Dispose method.


Author Comment

ID: 20354291
Hiya Bob, I see you around here an awful lot.

So what is the "best" way of doing this, or how is this commonly done? Is this something that I should even worry about?

It just seems like when I'm binding up a bunch of data in a class file, and letting that hang out there, .. well .. just doesn't seem efficient.

I've worked with more web companies than I can count, and most of what I've learned is on the job stuff and they all seem to do it the same way .. now that I'm building a my OWN site, I find myself thinking, "wait a minute, is this the RIGHT way to do it?"
LVL 96

Expert Comment

by:Bob Learned
ID: 20354460
The garbage collector makes your job significantly easier, but it is not the "perfect" way of memory management.  If you use a lot of global references that last the entire life-time of the application, or module-level references that get created indescriminately, you could run into some serious memory problems.  

A good rule of thumb, though, when developing software is to not worry about every little detail of memory management, and work more on the process details.  Then, you can use a profiler to monitor memory usage.  Sometimes worrying about memory management and other such optimization steps can make your program run slower.  

I read something the other day that there isn't any "right" or "wrong" way to build web sites, there is just a "better" way.   If the site does what you need, then it serves a purpose.  If it can look better, and perform faster, then it is a bonus!!  Studying, reading, talking, learning, experimenting, failing, and succeeding some ways that you can learn more about the "better way".

If you want to use static classes or methods, you can use them very carefully.  The life-time of static variables changes drastically with web sites, and server memory.  Using static methods with local instance variables is a perfectly good way of accessing methods without instance variables.



Author Comment

ID: 20354558
Bob, thanks for the dialogue.

The site is basically a Social Engineering type site. For example, on any given number of pages I need to pull repetitive data/code (user's photo, common controls), and then there is the whole personal profiling for people and their objects of possession .. there will likely be thousands of users, hundreds online at any given time, looking at other people's inventories, blogs, photo galleries, etc. All is heavily data-driven and customizable ... data caching will only take me so far since the data is so disparate.

I'm throwing pretty much everything that is reusable into class files to get the data, but it sounds like I might be better off considering user controls with the DAL closer to that... but then again, maybe .NET can handle the way I'm laying things out now. Arrrgh. :)

This is a project that I've been developing for 3 years, since ASP.NET 1.1 and I'm in the process of basically doing a total rewrite... looking for some "gotchas" in design and scalability. At the worst case I'll have a great DAL and everything well consolidated in one framework. The best case is that I'm dong the right thing and everything runs like a champ, but I guess I'm starting to get nervous.
LVL 96

Expert Comment

by:Bob Learned
ID: 20354592
It you are starting to feel nervous, then you need to think about stress testing your web site.

There are a few tools, and here is a representative list:

How do I stress test my ASP application?

There is the ACT (Application Center Test) for web applications from Microsoft:

INFO: Application Center Test (ACT) Tests Your Web Applications by Simulating Load


Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK ( for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question ( here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question