Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 726589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:28:09+00:00 2026-05-14T06:28:09+00:00

in my goal to adopt better coding practices I have a few questions in

  • 0

in my goal to adopt better coding practices I have a few questions in general about automatic handling of code. I have heard different answers both from online and talking with other developers/programmers at my work. I am not sure if I should have split them into 3 questions, but they all seem sort of related:

1) How does .NET handle instances of classes and other code things that take up memory? I recently found out about using the factory pattern for certain things like service classes so that they are only instantiated once in the entire application, but then I was told that ‘.NET handles a lot of that stuff automatically when mentioning it.’

2) How does Nhibernate’s session handle automatic clean-up of un-used things? I’ve seen some say that it is great at handling things automatically and you should just use a session factory and that’s it, no need to close it. But I have also read and seem many examples where people close the hibernate session.

3) How does LINQ’s datacontext handle this? Most of the time I never .disposed my datacontext’s and the app didn’t see to take a performance hit (though I am not running anything super intensively), but it seems like most people recommend disposing of your datacontext after you are done with it. However, I have seen many many code examples where the dispose method is never called. Also in general I found it kind of annoying that you couldn’t access even one-deep child related objects after disposing of the datacontext unless you explicity also grabbed them in the query.

Thanks all. I am loving this site so far, I kind of get lost and spend hours just reading things on here. =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T06:28:10+00:00Added an answer on May 14, 2026 at 6:28 am

    1) .NET does garbage collection and stuff but it doesn’t instantiate things once and provide them to you always, for this purpose you need an IoC Container like Autofac.

    2) session by itself doesn’t dispose itself off, you need to put it in a using block. But it does take care of other things that it manages.

    3) Its always a good idea to dispose of things, particularly unmanaged resources. So, as a rule of thumb put these kind of things in a using block.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Goal : I want flash to have accurate information about the width and height
I have successfully implemented code to plot multiple locations on google maps dynamically. Solution:
Goal: Get values which are unique in $resultSecond So I have two objects. $result
Goal: Rolling/Running total for all statements at the end of each month. Code: select
Goal: Display customized information based on end user's position. If you have 2 user:
Goal : I have a view which displays multiple nodes in full view including
Goal Detecting where comparisons between and copies of variables are made Inject code near
Goal: To launch VLC player through PHP code, and play the specified video in
Goal: Display different context menu if right clicking a row from the listview or
Here's my goal: have a table of data with edit/delete buttons. The edit buttons

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.