• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

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


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

  • 3
  • 2
1 Solution
Bob LearnedCommented:
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.

NauticalNonsenseAuthor Commented:
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?"
Bob LearnedCommented:
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.


NauticalNonsenseAuthor Commented:
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.
Bob LearnedCommented:
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

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

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now