You are right, I am going to provide you the code, most of it is generated
by Visual Stuido, all this program does is open an Oledbconnection and
closes that connection. This program takes 20M of RAM on my machine.
I know, most of this RAM is used by .NET memory managemnt and pooling
objects, I still believe that it is too high. If you minimize the program
and maximize it again, the working size is trimmed to about 4M.
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace WindowsApplicat ion4
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows. Forms.Form
{
private System.Data.Ole Db.OleDbDataAda pter oleDbDataAdapte r1;
private System.Data.Ole Db.OleDbCommand oleDbSelectComm and1;
private System.Data.Ole Db.OleDbCommand oleDbInsertComm and1;
private System.Data.Ole Db.OleDbCommand oleDbUpdateComm and1;
private System.Data.Ole Db.OleDbCommand oleDbDeleteComm and1;
private System.Data.Ole Db.OleDbConnect ion oleDbConnection 1;
private System.Windows. Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();
//
// TODO: Add any constructor code after InitializeCompo nent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeCompo nent()
{
this.oleDbDataA dapter1 = new System.Data.Ole Db.OleDbDataAda pter();
this.oleDbSelec tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbInser tCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbUpdat eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbDelet eCommand1 = new System.Data.Ole Db.OleDbCommand ();
this.oleDbConne ction1 = new System.Data.Ole Db.OleDbConnect ion();
this.button1 = new System.Windows. Forms.Button();
this.SuspendLay out();
//
// oleDbDataAdapte r1
//
this.oleDbDataA dapter1.DeleteC ommand = this.oleDbDelet eCommand1;
this.oleDbDataA dapter1.InsertC ommand = this.oleDbInser tCommand1;
this.oleDbDataA dapter1.SelectC ommand = this.oleDbSelec tCommand1;
this.oleDbDataA dapter1.TableMa ppings.AddRange (new
System.Data.Com mon.DataTableMa pping[] {
new System.Data.Com mon.DataTableMa pping("Table", "Generic", new
System.Data.Com mon.DataColumnM apping[] {
new System.Data.Com mon.DataColumnM apping("Generic ", "Generic"),
new System.Data.Com mon.DataColumnM apping("ID", "ID"),
new System.Data.Com mon.DataColumnM apping("NTE", "NTE"),
new System.Data.Com mon.DataColumnM apping("PinNum" , "PinNum"),
new System.Data.Com mon.DataColumnM apping("Stock", "Stock")})} );
this.oleDbDataA dapter1.UpdateC ommand = this.oleDbUpdat eCommand1;
//
// oleDbSelectComm and1
//
this.oleDbSelec tCommand1.Comma ndText = "SELECT Generic, ID, NTE, PinNum,
Stock FROM Generic";
this.oleDbSelec tCommand1.Conne ction = this.oleDbConne ction1;
//
// oleDbInsertComm and1
//
this.oleDbInser tCommand1.Comma ndText = "INSERT INTO Generic(Generic , NTE,
PinNum, Stock) VALUES (?, ?, ?, ?)";
this.oleDbInser tCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Generic",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Generic")) ;
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("NTE",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "NTE"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("PinNum",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "PinNum"));
this.oleDbInser tCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Stock",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Stock"));
//
// oleDbUpdateComm and1
//
this.oleDbUpdat eCommand1.Comma ndText = @"UPDATE Generic SET Generic = ?, NTE
= ?, PinNum = ?, Stock = ? WHERE (ID = ?) AND (Generic = ? OR ? IS NULL AND
Generic IS NULL) AND (NTE = ? OR ? IS NULL AND NTE IS NULL) AND (PinNum = ?
OR ? IS NULL AND PinNum IS NULL) AND (Stock = ? OR ? IS NULL AND Stock IS
NULL)";
this.oleDbUpdat eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Generic",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Generic")) ;
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("NTE",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "NTE"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("PinNum",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "PinNum"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Stock",
System.Data.Ole Db.OleDbType.Va rWChar, 50, "Stock"));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "ID", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ge neric",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Generic", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ge neric1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Generic", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_NT E",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "NTE", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_NT E1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "NTE", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Pi nNum",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "PinNum", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Pi nNum1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "PinNum", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_St ock",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Stock", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbUpdat eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_St ock1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Stock", System.Data.Dat aRowVersion.Ori ginal, null));
//
// oleDbDeleteComm and1
//
this.oleDbDelet eCommand1.Comma ndText = "DELETE FROM Generic WHERE (ID = ?)
AND (Generic = ? OR ? IS NULL AND Generic IS N" +
"ULL) AND (NTE = ? OR ? IS NULL AND NTE IS NULL) AND (PinNum = ? OR ? IS
NULL AND" +
" PinNum IS NULL) AND (Stock = ? OR ? IS NULL AND Stock IS NULL)";
this.oleDbDelet eCommand1.Conne ction = this.oleDbConne ction1;
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_ID ",
System.Data.Ole Db.OleDbType.In teger, 0,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "ID", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ge neric",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Generic", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Ge neric1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Generic", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_NT E",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "NTE", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_NT E1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "NTE", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Pi nNum",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "PinNum", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_Pi nNum1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "PinNum", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_St ock",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Stock", System.Data.Dat aRowVersion.Ori ginal, null));
this.oleDbDelet eCommand1.Param eters.Add(new
System.Data.Ole Db.OleDbParamet er("Original_St ock1",
System.Data.Ole Db.OleDbType.Va rWChar, 50,
System.Data.Par ameterDirection .Input, false, ((System.Byte)( 0)),
((System.Byte)( 0)), "Stock", System.Data.Dat aRowVersion.Ori ginal, null));
//
// oleDbConnection 1
//
this.oleDbConne ction1.Connecti onString = @"Jet OLEDB:Global Partial Bulk
Ops=2;Jet OLEDB:Registry Path=;Jet OLEDB:Database Locking Mode=1;Jet
OLEDB:Database Password=;Data
Source=""C:\Dat abase\Applicati onCore.mdb"";Pa ssword=;Jet OLEDB:Engine
Type=5;Jet OLEDB:Global Bulk
Transactions=1; Provider=""Micr osoft.Jet.OLEDB .4.0"";Jet OLEDB:System
database=;Jet OLEDB:SFP=False ;Extended Properties=;Mod e=Share Deny None;Jet
OLEDB:New Database Password=;Jet OLEDB:Create System Database=False; Jet
OLEDB:Don't Copy Locale on Compact=False;J et OLEDB:Compact Without Replica
Repair=False;Us er ID=Admin;Jet OLEDB:Encrypt Database=False" ;
//
// button1
//
this.button1.Lo cation = new System.Drawing. Point(96, 48);
this.button1.Na me = "button1";
this.button1.Ta bIndex = 0;
this.button1.Te xt = "button1";
this.button1.Cl ick += new System.EventHan dler(this.butto n1_Click);
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Controls.A dd(this.button1 );
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayo ut(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run (new Form1());
}
private void oleDbDataAdapte r1_RowUpdated(o bject sender,
System.Data.Ole Db.OleDbRowUpda tedEventArgs e)
{
}
private void button1_Click(o bject sender, System.EventArg s e)
{
oleDbConnection 1.Open();
oleDbConnection 1.Close();
}
}
}
"Scott M." <s-***@nospam.nosp am> wrote in message
news:eo******** ******@TK2MSFTN GP14.phx.gbl...
Thre is no code!
Just write a win form app that connects to Access or SQL server, open
the connection and closes it, you app will take between 15 to 20M
Well, I'd call what you've stated above some code. Let's see exactly what
you wrote because if I write code that does what you suggest, it doesn't
come anywhere near the memory usage you are experiencing.
Belive me I have coded my application very carefully and when I talk
about refrence couting I don't mean COM, I mean I make sure there are zero
refrences for an object, so the GC can collect it.
Although you say that I should "believe you" that you've coded carefully,
you continue to give us no examples of what you are doing. And, since
I've used .NET since early betas (nearly 4 years now) and have not experienced
what you are experiencing but have seen what you describe over and over
again with code that is not written properly, I'm going to have a hard
time just "beliving" that you are doing everything correctly.
It almost sounds like you don't want to solve your problem and would just
prefer to complain about .NET. Let's see your code!
"Scott M." <s-***@nospam.nosp am> wrote in message
news:um******** *******@TK2MSFT NGP12.phx.gbl.. . Well, from your comments it sounds like you might not fully understand
how
memory is managed in .NET. .NET does NOT use reference counters like
COM applications do.
Ultimately, it's not the Framework that is tying up memory, it is your
application. In any programming environment, if you write sloppy code,
you get poor performance. I'd start by examine your code and make sure you
are calling Dispose on any object that uses unmanaged resources, call Close
on
any object that is opened, manage any multi-threading you may be doing
with a watchful eye, use the Marshall.Releas eComObject class to allow the
Framework to release its references to any and ALL COM objects you may
be using, set the ASPCompat property of ASP.NET pages to True when using
COM objects in ASP.NET pages, etc. etc.
In short, before you beat up on the platform, examine what you are
doing in that platform. You haven't told us anything about the code you are
attempting to run. If you do, we can get a feel for how we may be able
to
help or point you in the right learning direction.
"Mike P" <m_******@hotma il.com> wrote in message
news:29******** ************@ne ws20.bellglobal .com...
>I know everything about reference counting and making sure you don't
>have
> large objects lying around. I have also profiled my app with multiple
> tools.
> I know about the fact GC collects memory but not necessary give it
back to > the OS.
>
>
>
> It seems that .NET win app will only return memory to the OS when the
> OS
> is
> asking for it. But!!! When the OS is asking for it is usually too
late, > tons
> of swapping and slow performance.
>
>
>
> I just don't get it, how can .NET a superior technology is eating so
much > RAM? I see that some people force their app to minimize or trim their
> workspace just to free the memory - that is a bad idea. Other people
> unload
> a application domain to save memory... a little better but still lots
> of
> work just to get some memory back to the OS.
>
>
>
> Some people tell me it is the price to pay for a runtime. Sorry, I
have > used
> other runtimes for windows applications and they don't eat so much
memory. > For the love of god, AcuCobol runtime does not take so much RAM (not
that > I
> want to code in COBOL now)
>
>
>
> At the end, it seems it is like running an OS within an OS. I am
> frustrated
> that a stupid windows application can take 20M for doing nothing, and
> if
> you
> have an app that does a little more stuff, it can take 40M and you
have to > worry about each Dispose and reference so it will not jump to 100M.
>
>
>
> and I am not alone with this problem....
>
>
>
>
http://www.dotnet247.com/247referenc.../14/73033.aspx >
>
>
>
>
>
>
>
>