|
Xpnctoc wrote: The application I am writing is very dialog-intensive.
I'm confused, is that a recommended User Interface Design?
Xpnctoc wrote: Does anyone know if the GC works on a time interval or a certain percentage of consumed memory, or what?
No. Nobody knows. Not even the guys at Microsoft that developed it, documented it and then published MSDN whitepapers, articles and blogs about how it works.
Xpnctoc wrote: Thanks for your help.
No problem
[modification] Sorry forgot to mention, don't try to use google to find any information on the subject, I am pretty sure that won't work. For example none of this would help[^]
|
|
|
|
|
If you don't trust the GC, then get out of .NET coding IMMEDIATELY! You'll
never sleep!
In addition to led mike's reply...
I didn't trust the GC when I started with C++/CLI. After 15+ years of C/C++, i am
VERY used to handling allocation/deallocation myself. I had to write a bunch of test code
to convince myself it worked. Maybe that will help you?
Managed objects WILL be freed eventually once no references are left on them. If you
mix unmanaged objects in managed classes you need to make absolutely sure you're using
destructors and finalizers properly and freeing any unmanaged resources. You are still
responsible for the scope of your managed objects. If they never go out of scope, they
will NOT be cleaned up by the GC.
The task manager is NOT a debugging/development tool.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Try this with a few WinForms apps(release builds of a C# apps). Start it up and watch the memory usage in task manager. Make sure you are not running the Visual Studio host process (appname.vshost.exe). Move it around and use the menu etc. and watch the memory usage climb until you have had enough fun with that. Now minimize it. After your initial "hmmm interesting" reaction, continue watch memory usage while you restore it and manipulate it some more.
Be sure to let me know what happens!
|
|
|
|
|
|
I know it's a C++ board. I posted it here because it is a C++/CLI application, and I was wondering if anyone else had encountered this phenomenon. But then after I had posted I got around to thinking it might be a more generic .NET issue. Sorry.
|
|
|
|
|
My reply was to led mike.
You are on the right board AFAIK
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: How high does it climb? Infinitely?
Well I get bored before I have any conclusive data. No doubt there are far better methods to actually test like with a profiler etc.
So anyway this is mildly interesting I have a utility app that I use to work with XML files XPath statements etc. I initially wrote it years ago in VC++ it uses MSXML and hosts the browser for one of the views. So like a year ago or so I remade it using C#. Now the new version is slightly more feature rich from a UI perspective and you would therefore expect a larger memory footprint but all in all they are very similar.
So you start the old VC++ app and it loads in at around 14 meg. After opening a few files and manipulating the UI to view stuff etc it grows up around 18 meg and you can see it freeing memory and it settles down just over 17 megs.
The C# app loads at just over 26 megs and you can get it to climb from there. But if you minimize it it drops to 1.1 meg! Then when you restore it it jumps up to 12 meg and as you begin to work it (open files and run XPath queries, manipulate the views etc.), it climbs up to just over 18 meg and you can see it free memory back down to just under 18 megs.
So overall the C# app has slightly more bells and whistles and uses a slightly larger memory footprint once you minimize it and restore it. I have no idea what that is all about but I wouldn't expect significant memory consumption from a .NET Windows Forms app. The UI is definitely not as responsive as the native app but memory consumption I would have to say is very similar.
Oh yeah I am running XP Pro
|
|
|
|
|
I understand that some things will be held on to because they don't go out of scope. But it seems to me there are some serious problems within the .NET framework not properly releasing references. Consider the behavior of the Menu control:
Every time I click my "File" menu (just as an illustration), MORE memory is sucked up to generate the drop down (New, Open, Save, etc...). Sure, the Menu control never goes out of scope as long as the application is run, but why does it grab more memory every time? It seems to me that after the memory has been allocated once, that should be the end of it. If I call up the "File" menu a second time, there should be no reference left to the original fly-out. The memory consumption should stay constant because one reference was destroyed and one was created. But no. The framework sucks up the additional memory to create a new reference without reliquishing the old reference.
As many times as I expand any menu item, more memory is consumed. None is ever reliquished. And, as I stated in my original post, I took my unmanaged data out of the equasion. I'm talking about just running an application form with a menu system -- before I do any of the real application work or allocate any of the core data structure memory.
If .NET won't release any of the consumed Menu memory before application termination, then I might as well go back to VS6. That's just too sloppy.
|
|
|
|
|
AFAIK, the GC will kick-in whenever it feels like working or when a low memory situation. In my little world, I have never had a .NET application run out of memory that they gobbled up!
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
Like I mentioned to led mike, I don't use .NET GUI so I can't comment on the
specifics of your situation..
If I remember correctly from my tests, in an infinite loop allocating objects on the managed heap
and watching in the task manager, memory use would climb to around 300MB between each cleanup
by the GC. That was VS2003/.NET 1.1. Strangely, I cannot replicate that with VS2005 LOL
I'm trying to make an infinite loop that allocates and the memory never moves.
If you need to keep everything cleaned up immediately, Does GC.Collect() help?
If this stuff leaks why isn't everyone screaming about it? I would think by now
someone would have noticed. .NET would indeed be useless.
Cheers!
MArk
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Also, you can minimize memory usage in .NET by cutting back in the creation of mulitple or temporary small objects. For example, instead of doing a lot of string manipulations on a String , use a StringBuilder object instead.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I am aware of a few optimizations such as the use of StringBuilder. The behavior I noted is more apparent in items that are beyond my control -- such as the Menu control. Why should more memory be allocated every time a fly-out is invoked, yet when the fly-out disappears no memory is ever released?
However, I posted a similar thread on another board, and one of the respondants said that I'm looking at this all wrong. I have only Task Manager to gauge memory use, but he said I can't do that because a .NET application runs inside of a "virtual machine". Therefore Task Manager shows only what the VM is reserving, not necessarily what I'm using.
I only half-way buy this idea. Regardless whether .NET is running a VM or not, the fact is that every time I invoke a menu, or a dialog box, the Task Manager numbers go up. The respondant's point was that the number in TM will NOT go down because the VM has reserved that memory. Well fine. But if the memory is reserved, they why does it need to reserve even MORE memory the next time I trigger a fly-out menu? The memory was already reserved once. If the memory was truly freed after the fly-out disappeared the first time, the virt. mach. should not need to compound its memory reservation.
From that angle, it seems to me that Task Manager is indicating there is something wrong with .NET's virt. machine. BUT Mark has a very valid point that if there was truly something to be worried about, it seems like there would be a lot more people screaming about it.
The overwhelming opinion on this and other message boards is that I'm worried about nothing. I guess I don't know enough about .NET internals. All I know is that the numbers I saw in Task Mgr don't make a lot of sense, so I thought I'd inquire about it.
|
|
|
|
|
Your concern is quite natural and valid. I do not like to see wasted resources. However, I think the ultimate goal of the GC is efficiency over resource conservation. If the GC is constantly reclaiming and defragmenting memory, your application speed will suffer. You, as a programmer, gain freedom from resource management, but the trade off is this management is in a black box, and various opinions on what is going on in this black box.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I am trying to put information in an access database file (mdb) with an oledb connection. Everything seems fine but no new information is added to the database at the end.
This is the code I have now:
double Tabel_Panelinfo(String^ item_id, String^ use, String^ type)
{
int dblID = 10;
OleDbConnection^ myOleDbConnection = nullptr;
try
{
OleDbConnectionStringBuilder^ connectionBuilder = gcnew OleDbConnectionStringBuilder();
connectionBuilder->Provider = "Microsoft.Jet.OLEDB.4.0";
connectionBuilder->DataSource = "D:\\Data\\Visual Studio 2005\\Projects\\VertexBDXML-RandekSPL728\\VertexBDXML-RandekSPL728\\Tabel-XML.mdb";
myOleDbConnection = gcnew OleDbConnection(connectionBuilder->ToString());
myOleDbConnection->Open();
OleDbDataAdapter^ DataAdapter = gcnew OleDbDataAdapter("SELECT * FROM tblPanel", myOleDbConnection);
DataAdapter->FillError += gcnew FillErrorEventHandler(MyEventHandler::FillError);
DataAdapter->RowUpdated += gcnew OleDbRowUpdatedEventHandler(MyEventHandler::RowUpdated);
DataSet^ myDataSet = gcnew DataSet();
DataAdapter->MissingSchemaAction = MissingSchemaAction::Add;
DataAdapter->Fill(myDataSet, "tblPanel");
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
if (row != nullptr)
{
row["item_id"] = item_id;
row["use"] = use;
row["type"] = Convert::ToInt16(type);
DataAdapter->Update(myDataSet, "tblPanel");
}
}
catch(Exception^ e)
{
Console::WriteLine(e->Message);
}
finally
{
if ( myOleDbConnection != nullptr )
myOleDbConnection->Close();
}
return dblID;
}
Stefan
|
|
|
|
|
This is the managed C++ forum (as clearly stated on this page) and therefore the wrong forum for this question. Make sure you are using some sort of tutorial or example, there are many database articles here on code project (use the site navigation ). When you repost your question in the correct forum (Visual C++ / MFC ) be sure to reference the article or tutorial you are working from.
|
|
|
|
|
he's in the right forum, he's clearly using C++/CLI and not native C++.
|
|
|
|
|
ooops
apparently I have been brainwashed. I went off the subject.
|
|
|
|
|
|
I might be the only member stupid enough to pull that off!
Happy Friday... I'm out of here
|
|
|
|
|
See if adding the row to the table does it.
myDataSet->Tables["tblPanel"]->Rows->Add(row);
|
|
|
|
|
This still does not work, i added it in between the other code.
I now get exception for e { "Index was outside the bounds of the array."}
Is there maybe a good example to write information to an access database using C++.
I have found many examples but cannot find any that works in my project.
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
myDataSet->Tables["tblPanel"]->Rows->Add(row);
if (row != nullptr)
{
row["ID"] = dblID;
row["item_id"] = item_id;
row["use"] = use;
row["type"] = Convert::ToInt16(type);
DataAdapter->Update(myDataSet, "tblPanel");
}
Stefan
|
|
|
|
|
I finally found the error that prevented me from adding the data.
I have used this code:
DataTable^ MyTable = myDataSet->Tables[0];
DataRow^ row = MyTable->Rows->Add();
instead of this:
DataRow^ row = myDataSet->Tables["tblPanel"]->NewRow();
Stefan
|
|
|
|
|
Is there a way for me to create a listview hearder spanning 2 rows using C/C++. If there is, then I would appreciate it if someone can provide me with some code snippit.
|
|
|
|
|
try inserting a newline character in header name
|
|
|
|
|
I tried that and it didn't work.
|
|
|
|