Question about datatable objects and releasing resources for same

Posted on 2011-04-27
Last Modified: 2012-05-11
I have a database helper class that returns a datatable to the calling method. In that database helper class function, I open the connection, load the newly declared datatable, close the connection and then return the table.

My question is what keeps this from causing problems with creating a new datatable each time this is called. Couldn't I possibly run out of resources if done hundreds or thousands of times?

If I set the datatable to nothing in the calling method when I'm finished does that take care of releasing the resources created in the database helper class?
Question by:rutledgj
    LVL 18

    Accepted Solution

    When an object is no longer referenced, it is marked for cleanup by the garbage collection process.  This happens automatically in a separate thread.  You can force the garbage collection to run with GC.Collect()

    LVL 83

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
    Introduction When many people think of the WebBrowser ( control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now