Home All Groups Group Topic Archive Search About

Memory never released in SMO (when create database)

Author
11 May 2007 3:01 PM
Hao
I have a simple application to create an empty SQL Server database (no
table) in C# trying smo. I believe I closed all connections and also forced
garbage collection.
Why did I see memory increased by at least 9M (from 17MB to 26MB) and never
came back?
Is it by design?

My goal is to create thousands of tables and hundreds of databases. I ran
into problems when the code actually consumed about 2G memory. Now I tried
to simplify the code to find the memory issue.

Thanks.
Hao

Author
11 May 2007 4:03 PM
Hao
Here is the testing code.

static void Main(string[] args)

{

if (true)

{

// Connect to the local, default instance of SQL Server.

Server srv = new Server();

// Define a Database object variable by supplying the server and the
database name arguments in the constructor.

Database db = new Database(srv, "Test_SMO_Database");

// Create the database on the instance of SQL Server.

db.Create();

Console.WriteLine(db.CreateDate.ToString());

}



GC.Collect();


GC.WaitForPendingFinalizers();

Console.Read();

return;

}

Show quote
"Hao" <Hao@newsgroup.nospam> wrote in message
news:egr6E19kHHA.4516@TK2MSFTNGP03.phx.gbl...
>I have a simple application to create an empty SQL Server database (no
>table) in C# trying smo. I believe I closed all connections and also forced
>garbage collection.
> Why did I see memory increased by at least 9M (from 17MB to 26MB) and
> never came back?
> Is it by design?
>
> My goal is to create thousands of tables and hundreds of databases. I ran
> into problems when the code actually consumed about 2G memory. Now I tried
> to simplify the code to find the memory issue.
>
> Thanks.
> Hao
>
Author
12 May 2007 11:37 PM
Alvin Bruney [MVP]
You don't need to do that GC collect and pendingfinalizer stuff. I see that
code on the net a lot and it is mostly incorrect. What you need to do is
close your open connections which it seems like you aren't doing so there's
no benefit in calling gc collect because you still have roots. Most
probably, your open connections, command objects and readers are not being
de-allocated properly.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


Show quote
"Hao" <Hao@newsgroup.nospam> wrote in message
news:%23S6mvX%23kHHA.208@TK2MSFTNGP05.phx.gbl...
> Here is the testing code.
>
> static void Main(string[] args)
>
> {
>
> if (true)
>
> {
>
> // Connect to the local, default instance of SQL Server.
>
> Server srv = new Server();
>
> // Define a Database object variable by supplying the server and the
> database name arguments in the constructor.
>
> Database db = new Database(srv, "Test_SMO_Database");
>
> // Create the database on the instance of SQL Server.
>
> db.Create();
>
> Console.WriteLine(db.CreateDate.ToString());
>
> }
>
>
>
> GC.Collect();
>
>
> GC.WaitForPendingFinalizers();
>
> Console.Read();
>
> return;
>
> }
>
> "Hao" <Hao@newsgroup.nospam> wrote in message
> news:egr6E19kHHA.4516@TK2MSFTNGP03.phx.gbl...
>>I have a simple application to create an empty SQL Server database (no
>>table) in C# trying smo. I believe I closed all connections and also
>>forced garbage collection.
>> Why did I see memory increased by at least 9M (from 17MB to 26MB) and
>> never came back?
>> Is it by design?
>>
>> My goal is to create thousands of tables and hundreds of databases. I ran
>> into problems when the code actually consumed about 2G memory. Now I
>> tried to simplify the code to find the memory issue.
>>
>> Thanks.
>> Hao
>>
>
>

AddThis Social Bookmark Button