Click here to Skip to main content
15,917,542 members
Home / Discussions / C#
   

C#

 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
Joe Woodbury15-Mar-06 7:46
professionalJoe Woodbury15-Mar-06 7:46 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
Daniel Grunwald15-Mar-06 8:27
Daniel Grunwald15-Mar-06 8:27 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
mcljava15-Mar-06 11:43
mcljava15-Mar-06 11:43 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
mcljava15-Mar-06 12:16
mcljava15-Mar-06 12:16 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
Dave Doknjas15-Mar-06 13:48
Dave Doknjas15-Mar-06 13:48 
AnswerRe: Convert VB.NET 2005 to C#.NET 2005 Pin
angelagke15-Mar-06 15:40
angelagke15-Mar-06 15:40 
QuestionTabControl Pin
Sabry190515-Mar-06 5:15
Sabry190515-Mar-06 5:15 
QuestionGarbage Collection needed? Pin
Glenn E. Lanier II15-Mar-06 4:57
Glenn E. Lanier II15-Mar-06 4:57 
I have created a class to hold some related data (ResultsOfTest). I am reading a record from an Access file, loading the data into the members of the ResultsOfTest class, then inserting into a database.

This works properly, except I am consuming massive amounts of memory. My understanding was the memory would be released when the new'ed object went out of scope (which should be at the end of the while loop). This doesn't seem to be the case, so I stuck in a garbage collection collect call every 1000 iterations. This doesn't seem to have any effect on the memory consumption.

while (readerAccess.Read())
{
	ResultsOfTest testResult = new ResultsOfTest();
	try
	{
		if (!readerAccess.IsDBNull(iTestIndex)) { testResult.TestID = Convert.ToDecimal(readerAccess.GetInt32(iTestIndex)); }
		if (!readerAccess.IsDBNull(iEmployeeIndex)) { testResult.EmployeeID = Convert.ToDecimal(readerAccess.GetInt32(iEmployeeIndex)); }
		if (!readerAccess.IsDBNull(iTestDateIndex)) { testResult.DateOfTest = readerAccess.GetDateTime(iTestDateIndex); }
		if (!readerAccess.IsDBNull(iReasonIndex)) { testResult.ReasonForTest = Convert.ToDecimal(readerAccess.GetInt32(iReasonIndex)); }
		if (!readerAccess.IsDBNull(iDeferredDateIndex)) { testResult.DeferredDate = readerAccess.GetDateTime(iDeferredDateIndex); }
		if (!readerAccess.IsDBNull(iReadDateIndex)) { testResult.ReadDate = readerAccess.GetDateTime(iReadDateIndex); }
		if (!readerAccess.IsDBNull(iResultIndex)) { testResult.TestResultCode = Convert.ToDecimal(readerAccess.GetInt32(iResultIndex)); }
		if (!readerAccess.IsDBNull(iCommentIndex)) { testResult.Comments = readerAccess.GetString(iCommentIndex); }
		iRecordsRead++;
	}
	catch (OleDbException odex)
	{
		logger.Error("Unable to read record from Access db. {0}", odex.ToString());
	}
	if (testResult.TestID > 0)
	{
		if (db.UpdateTestResults(ref testResult))
		{
			iRecordsWritten++;
		}
	}
	if ((iRecordsRead % 1000) == 0)
	{
		StatusScreen.SetStatus("Garbage collection in process...");
		GC.Collect();
	}
}


What can/should I do differently, so the program will release the un-needed memory?

Thanks,
Glenn

-- modified at 10:57 Wednesday 15th March, 2006 (placed pre inside the code marker)
AnswerRe: Garbage Collection needed? Pin
Colin Angus Mackay15-Mar-06 6:02
Colin Angus Mackay15-Mar-06 6:02 
GeneralRe: Garbage Collection needed? Pin
Glenn E. Lanier II15-Mar-06 6:15
Glenn E. Lanier II15-Mar-06 6:15 
AnswerRe: Garbage Collection needed? Pin
Judah Gabriel Himango15-Mar-06 7:06
sponsorJudah Gabriel Himango15-Mar-06 7:06 
GeneralRe: Garbage Collection needed? Pin
Glenn E. Lanier II15-Mar-06 8:39
Glenn E. Lanier II15-Mar-06 8:39 
GeneralRe: Garbage Collection needed? Pin
Judah Gabriel Himango15-Mar-06 9:00
sponsorJudah Gabriel Himango15-Mar-06 9:00 
GeneralRe: Garbage Collection needed? Pin
Glenn E. Lanier II15-Mar-06 8:44
Glenn E. Lanier II15-Mar-06 8:44 
QuestionHow to print a C# form Pin
JuJAngel15-Mar-06 3:56
JuJAngel15-Mar-06 3:56 
AnswerRe: How to print a C# form Pin
Ed.Poore15-Mar-06 6:47
Ed.Poore15-Mar-06 6:47 
GeneralRe: How to print a C# form Pin
JuJAngel18-Mar-06 9:36
JuJAngel18-Mar-06 9:36 
GeneralRe: How to print a C# form Pin
Ed.Poore18-Mar-06 10:45
Ed.Poore18-Mar-06 10:45 
Questionhow to do "123=6 23567=23"??? Pin
gursucan15-Mar-06 3:56
gursucan15-Mar-06 3:56 
AnswerRe: how to do "123=6 23567=23"??? Pin
Guffa15-Mar-06 4:03
Guffa15-Mar-06 4:03 
AnswerRe: how to do "123=6 23567=23"??? Pin
Lju215-Mar-06 9:07
Lju215-Mar-06 9:07 
AnswerRe: how to do "123=6 23567=23"??? Pin
Luis Alonso Ramos15-Mar-06 18:49
Luis Alonso Ramos15-Mar-06 18:49 
QuestionHow to do syntax hightlighting? Pin
SirErugor15-Mar-06 3:26
SirErugor15-Mar-06 3:26 
AnswerRe: How to do syntax hightlighting? Pin
Ed.Poore15-Mar-06 5:41
Ed.Poore15-Mar-06 5:41 
GeneralRe: How to do syntax hightlighting? Pin
SirErugor15-Mar-06 5:48
SirErugor15-Mar-06 5:48 

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.