Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. Memory leak issue.

Memory leak issue.

Scheduled Pinned Locked Moved .NET (Core and Framework)
databaseperformancehelpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PSK_
    wrote on last edited by
    #1

    Hi all, I have created a scheduling service which runs all the time, I am having a query regarding following set of code. private DataSet GetDataSet() { DataSet excelDataSet = new DataSet(); OleDbConnection excelConnection = new OleDbConnection(myConnectionString); OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM " +fileName, excelConnection); OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand); excelConnection.Open(); excelAdapter.Fill(excelDataSet); if (excelConnection.State == ConnectionState.Open) excelConnection.Close(); return excelDataSet; } Do I need to call dispose on OleDbDataAdapter and OleDbConnection connection object to avoid memory leaks or garbage collector will take care of this?

    Regards, Prakash Kalakoti

    N 1 Reply Last reply
    0
    • P PSK_

      Hi all, I have created a scheduling service which runs all the time, I am having a query regarding following set of code. private DataSet GetDataSet() { DataSet excelDataSet = new DataSet(); OleDbConnection excelConnection = new OleDbConnection(myConnectionString); OleDbCommand excelCommand = new OleDbCommand(@"SELECT * FROM " +fileName, excelConnection); OleDbDataAdapter excelAdapter = new OleDbDataAdapter(excelCommand); excelConnection.Open(); excelAdapter.Fill(excelDataSet); if (excelConnection.State == ConnectionState.Open) excelConnection.Close(); return excelDataSet; } Do I need to call dispose on OleDbDataAdapter and OleDbConnection connection object to avoid memory leaks or garbage collector will take care of this?

      Regards, Prakash Kalakoti

      N Offline
      N Offline
      nitikin
      wrote on last edited by
      #2

      Though the GC would collect all of the allocated managed memory periodically, its best to dispose off the DB objects when you are done. Your code should have been in the lines of : using(OleDbConnection excelConnection = new ...) { etc etc }

      namaste, Nitin Koshy http://devwaves.blogspot.com ...and I thought I knew

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups