Click here to Skip to main content
15,881,380 members
Home / Discussions / C#
   

C#

 
AnswerRe: Getting this Error message....any one know y??? Pin
DaveyM6911-Mar-09 14:56
professionalDaveyM6911-Mar-09 14:56 
GeneralRe: Getting this Error message....any one know y??? Pin
S K Y11-Mar-09 15:26
S K Y11-Mar-09 15:26 
GeneralRe: Getting this Error message....any one know y??? Pin
DaveyM6911-Mar-09 15:34
professionalDaveyM6911-Mar-09 15:34 
GeneralRe: Getting this Error message....any one know y??? Pin
Christian Graus11-Mar-09 15:58
protectorChristian Graus11-Mar-09 15:58 
GeneralRe: Getting this Error message....any one know y??? Pin
S K Y11-Mar-09 18:18
S K Y11-Mar-09 18:18 
QuestionHow to use OleDbConnection or SqlCommand to read Schema and database records [modified] Pin
granthamlee11-Mar-09 14:30
granthamlee11-Mar-09 14:30 
QuestionSyste.OutOfMemoryException Pin
Member 461797111-Mar-09 14:23
Member 461797111-Mar-09 14:23 
AnswerRe: Syste.OutOfMemoryException [modified] Pin
Luc Pattyn11-Mar-09 14:34
sitebuilderLuc Pattyn11-Mar-09 14:34 
Hi Jon,

adding some GC.Collect() calls is not the way to fix programming mistakes. What you need to do is call Dispose() on those objects you don't need any longer, provided their class has such a method.

In your case, insertLib = new OleDbCommand(insSql, musLibConn); is the most likely culprit: inside the loop you create OleDbCommand instances, use them, then let them fade into oblivia (by assigning a new OleDbCommand to insertLib, the old one is gone, but still occupies memory.

I suggest you do not declare OleDbCommand insertLib; outside the foreach loop, instead do
foreach (...) {
  OleDbCommand insertLib=new OleDbCommand(...);
  ...
  insertLib.Dispose();
}

that makes it perfectly clear the OleDbCommand is always created, used, disposed.

I am not familiar with some of the classes you are using (e.g. ID3Info), chances are they also have a Dispose() and need the same treatment.

ADDED
There is a useful construct that automates the above, like so:
foreach (...) {
  using (OleDbCommand insertLib=new OleDbCommand(...)) {
     ...
  }
}


The advantages are it takes less code, and the Dispose is guaranteed to occur, even when an exception gets thrown inside the using block.
/ADDED


Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets


modified on Wednesday, March 11, 2009 8:43 PM

AnswerRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 14:40
professionalDaveyM6911-Mar-09 14:40 
AnswerRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 14:45
professionalDaveyM6911-Mar-09 14:45 
AnswerRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 14:48
Member 461797111-Mar-09 14:48 
GeneralRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 14:52
professionalDaveyM6911-Mar-09 14:52 
GeneralRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 14:59
Member 461797111-Mar-09 14:59 
GeneralRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 15:26
professionalDaveyM6911-Mar-09 15:26 
GeneralRe: Syste.OutOfMemoryException Pin
Luc Pattyn11-Mar-09 15:46
sitebuilderLuc Pattyn11-Mar-09 15:46 
GeneralRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 15:56
professionalDaveyM6911-Mar-09 15:56 
GeneralRe: Syste.OutOfMemoryException Pin
Luc Pattyn11-Mar-09 16:06
sitebuilderLuc Pattyn11-Mar-09 16:06 
GeneralRe: Syste.OutOfMemoryException Pin
DaveyM6911-Mar-09 23:03
professionalDaveyM6911-Mar-09 23:03 
GeneralRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 15:06
Member 461797111-Mar-09 15:06 
GeneralRe: Syste.OutOfMemoryException Pin
Luc Pattyn11-Mar-09 15:13
sitebuilderLuc Pattyn11-Mar-09 15:13 
GeneralRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 15:16
Member 461797111-Mar-09 15:16 
GeneralRe: Syste.OutOfMemoryException [modified] Pin
Luc Pattyn11-Mar-09 15:49
sitebuilderLuc Pattyn11-Mar-09 15:49 
GeneralRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 16:53
Member 461797111-Mar-09 16:53 
GeneralRe: Syste.OutOfMemoryException Pin
Luc Pattyn11-Mar-09 16:10
sitebuilderLuc Pattyn11-Mar-09 16:10 
GeneralRe: Syste.OutOfMemoryException Pin
Member 461797111-Mar-09 16:55
Member 461797111-Mar-09 16:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.