473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Concerning Garbage Collection in Managed C++

Hello,
I am developing a console application in Managed C++
with Visual Studio .Net. I am trying to learn how to
correctly destroy variables. When I run my program, with
every added action, the memory usage increases but the
only memory being allocated in each function is for
temporary local variables, and should not persist.
Calling the garbage collector does not seem to do anything
to clean up the memory usage. I am currently setting each
variable back to NULL upon leaving the functions, but it
does not seem to be working. Are variables in Managed C++
not cleaned up when they go out of scope? Am I supposed
to take extra precautions to get them to be released? Is
there any way for me to find out what is leaking?

Thank you for your help,
Tim
Nov 17 '05 #1
2 1610
Hi again,
I got some help tracking the problem down and now know
that the variable that is leaking memory is an
OleDBDataReader - I close it, but all of the memory that
was allocated for it remains. Any ideas on how to clear
this up? I need to keep the database connection open.

Thanks,
Tim
-----Original Message-----
Hello,
I am developing a console application in Managed C++
with Visual Studio .Net. I am trying to learn how to
correctly destroy variables. When I run my program, with
every added action, the memory usage increases but the
only memory being allocated in each function is for
temporary local variables, and should not persist.
Calling the garbage collector does not seem to do anythingto clean up the memory usage. I am currently setting eachvariable back to NULL upon leaving the functions, but it
does not seem to be working. Are variables in Managed C++not cleaned up when they go out of scope? Am I supposed
to take extra precautions to get them to be released? Is
there any way for me to find out what is leaking?

Thank you for your help,
Tim
.

Nov 17 '05 #2
<an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
Hi again,
I got some help tracking the problem down and now know
that the variable that is leaking memory is an
OleDBDataReader - I close it, but all of the memory that
was allocated for it remains. Any ideas on how to clear
this up? I need to keep the database connection open.


Are you referring to .Close()ing it or to setting the variable to null and
it being garbage collected?

If you mean .Close(), it is possible that the memory used is held onto in
case of another .Open(). If you mean you're setting the variable to null
(or it goes out of scope, or you .Dispose() it), the garbage collector runs
in a non-deterministic manner, meaning it will deallocate the memory
whenever it feels like it and you needn't be concerned.
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JC | last post by:
How does garbage collection work in C# and VB.NET for data returned from COM object? For example, a COM object written in C++ returns a SAFEARRAY to C# or VB.NET, will this SAFEARRAY (mapped to...
5
by: Laser Lu | last post by:
What doese Garbage Collection mean? And what is Managed Code? Any links to relevant articles or resources would be appreciated! -- Best regards, Laser Lu
2
by: Oculus | last post by:
Before I get into the question -- I know .NET isn't the right solution for this app but it's part of my clients requirements and writing this in C++ isn't an option. That being said -- my app is a...
4
by: Chris | last post by:
Hi, I think I'm having some problems here with garbage collection. Currently, I have the following code: public struct Event { public int timestamp;
5
by: Bob lazarchik | last post by:
Hello: We are considering developing a time critical system in C#. Our tool used in Semiconductor production and we need to be able to take meaurements at precise 10.0 ms intervals( 1000...
2
by: Howard Weiss | last post by:
I am writing a Managed C++ application. In my application, I create a modeless sub-form using New. I retain a pointer to this sub-form in my application. If the user closes this form, my...
5
by: R. MacDonald | last post by:
Hello, all, I am currently working on a .Net (VB) application that invokes routines in unmanaged (Fortran) DLLs. The unmanaged routines then communicate with the .Net application by means of a...
56
by: Johnny E. Jensen | last post by:
Hellow I'am not sure what to think about the Garbage Collector. I have a Class OutlookObject, It have two private variables. Private Microsoft.Office.Interop.Outlook.Application _Application =...
158
by: pushpakulkar | last post by:
Hi all, Is garbage collection possible in C++. It doesn't come as part of language support. Is there any specific reason for the same due to the way the language is designed. Or it is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.