473,386 Members | 1,698 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,386 software developers and data experts.

c# compiler mem"leakage"

Lets consider following code:

while (true)
{
string[] t = new String[1024 * 1024 * 20];
}

You probably thing this is the good solution because "narrow scope of
variable to the minimum". But wait. Mem usage is at level of 300MiB!

Now. Lets see what happens if we use:

string[] t;
while (true)
{
t = null;
t = new String[1024 * 1024 * 20];
}
Wow! Now mem is something at 30MiB. Who could know that?
So this is either compiler bug or framework's thing.

By the way: Add GC.Collect() for your VS not to hang up for a moment
when you stop or pause. Do it like that:
string[] t;
while (true)
{
t = null;
GC.Collect();
t = new String[1024 * 1024 * 20];
}
Sep 4 '07 #1
3 1189
Doker <do****@wp.plwrote:
Lets consider following code:

while (true)
{
string[] t = new String[1024 * 1024 * 20];
}

You probably thing this is the good solution because "narrow scope of
variable to the minimum". But wait. Mem usage is at level of 300MiB!
Hmm. I don't see that at all. Are you seeing it when you run in the
debugger, or in release mode? How are you measuring the memory usage?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 4 '07 #2
Jon Skeet [C# MVP] pisze:
Doker <do****@wp.plwrote:
>Lets consider following code:

while (true)
{
string[] t = new String[1024 * 1024 * 20];
}

You probably thing this is the good solution because "narrow scope of
variable to the minimum". But wait. Mem usage is at level of 300MiB!

Hmm. I don't see that at all. Are you seeing it when you run in the
debugger, or in release mode? How are you measuring the memory usage?
Try in debug mode. I see it in Task manager by the app name entry.
Vista x64, VS SP1.
Sep 5 '07 #3
On Sep 5, 9:49 am, Doker <dok...@wp.plwrote:
Hmm. I don't see that at all. Are you seeing it when you run in the
debugger, or in release mode? How are you measuring the memory usage?

Try in debug mode. I see it in Task manager by the app name entry.
Vista x64, VS SP1.
When you run something in debug mode, that changes the garbage
collection behaviour in subtle ways. If it's not a problem when
running outside the debugger, I'm not sure that I really view it as an
issue.

Jon

Sep 5 '07 #4

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

Similar topics

205
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.