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

Posted on 2007-11-26
Medium Priority
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
SingleRun is a tool that ensures that only one instance of an application is started, running it again brings the application to focus.
How to fix display issue, screen flickering issue when I plug in power cord to the machine. Before I start explaining the solution lets check out once the issue how it looks like after I connect the power cord. most of you also have faced this…
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

624 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