473,830 Members | 2,326 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to use Using

cj
I'm looking at using Using to try an plug a suspected memory leak. I've
already started using dispose for everything that implements it but no
luck. I have several questions about Using

Can I nest using?

I take it using only applies to resources that it was given as
parameters and will not help with those dimmed inside a using block. Right?

I guess I'm still supposed to close and dispose sql connections and
close files etc before end using?
Jun 22 '07
13 1388
cj
Rory and Cor, yes Taskmanager does show the same thing Rory is seeing
and after over 2 weeks of use the operating system issues a warning
about page file or virtual memory almost full (I wasn't the one who saw
the message so I can't say specifically what it said).

I am currently using perfmon to track the problem an I see:

# Bytes in All Heaps fluctuates but has shown no signs of increase
Large Object Heap Size hasn't changed since it started
% Time in GC has fluctuated but shown no upward trend and is very small
Avg .004

Private bytes continues to climb whenever the system is active
Working Set also continues to climb at the same rate as private bytes
Virtual Bytes continues to climb in a stair step fashion--jumps up every
few hours.
Thread Count fluctuates but shows no upward trend Avg 15

Cor, I have a post titled "multithrea ded tcp/ip server large page file"
that has quite a history if you want to know more. I've been working
with Charles Wang to try to solve the memory problems. If you wish to
offer suggestions on memory leaks I'd be glad to hear them but I think
it'd be best to put them in respose to my other post. This post was
intended only to determine how to use using.
Rory Becker wrote:
>cj,

How do you know that you have a memory leak. And please don't tell me
that you have seen that in the taskmanager, one look at Google gives
you thousends of responses that that says nothing.

Cor

On a very slightly related point....

Cor... I'm curious... I have observed processes in Taskmanager (in this
case not .Net but Ruby) which appeared to eternally use greater and
greater quantities of memory (presumably)as time goes on.
I can understand that due to garbage collection issues (in either Ruby
or .Net) that taskmanager's absolute concept of memory usage for a given
process can be way off.

However, when memory keeps going up and up and up, it becomes fairly
clear that something is up.

Now granted, I have no Idea if this is what the OP is experiencing, but
doesn't this mean that TaskManager isn't entirely useless in detecting
at least the existence of a problem?

--
Rory
Jun 25 '07 #11
On Jun 25, 6:46 am, cj <c...@nospam.no spamwrote:
Thanks! One little followup. When you say I don't have to call
closing, is that because end using calls the cleanup method?
That's correct. Using is really syntactic sugar for:

Dim disposableObjec t As DisposableResou rce
Try
disposableObjec t.UseResource
Finally
If Not disposableObjec t Is Nothing Then
disposableObjec t.Dispose
End Try

Using is simply a cleaner way to guarentee that your resource will be
cleaned up - no matter how the block is exited.

--
Tom Shelton

Jun 25 '07 #12
cj
Let me see if I understand this fully. Actually dimming an sql
connection uses no resources. The resources are acquired when .open or
..fill etc are used. .Close and .dispose (apparently are the same thing)
relinquish the resources but don't undim it therefore things like
mysqlconnection .connectionstri ng = ... still remain in memory and if
another open or fill is encountered new resources are acquired. Correct?

Tom Shelton wrote:
On Jun 25, 6:46 am, cj <c...@nospam.no spamwrote:
>Thanks! One little followup. When you say I don't have to call
closing, is that because end using calls the cleanup method?

That's correct. Using is really syntactic sugar for:

Dim disposableObjec t As DisposableResou rce
Try
disposableObjec t.UseResource
Finally
If Not disposableObjec t Is Nothing Then
disposableObjec t.Dispose
End Try

Using is simply a cleaner way to guarentee that your resource will be
cleaned up - no matter how the block is exited.

--
Tom Shelton
Jun 25 '07 #13
Hi Cj,

Yes, normally, the resource in your description means unmanaged resource
encapsulated by the managed object. The unmanaged resource includes file
handle, bitmap resource, network/sql connections, window handle etc... .Net
GC can use the metadata to know how to collect the managed object space on
the heap, however, it knows nothing about the unmanaged resource, so the
designer of the class needs to implement the IDispose interface to tell the
developer to release the unmanaged resource.

Regarding SqlConnection, its unmanaged resource is the connection to the
SQL Server and this connection will normally be started by Open method. So
SqlConnection.O pen method will allocate the unmanaged resource, and the
calling to Dispose and Close method is required to release it. However,
SqlConnection.C onnectionString is a managed string object, which is known
to GC. So it has nothing to do with Dispose/Close method. It will be freed
by .Net GC when there is not references from root to point to the
SqlConnection.

Hope this is clear.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 26 '07 #14

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

Similar topics

5
5723
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ================================================================= Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'. using std::string; ^^^
3
2167
by: Mike L | last post by:
Should the command call "using" be before or after my namespace? **AFTER** namespace DataGridBrowser { using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Collections;
3
2445
by: xzzy | last post by:
I was wondering why we have to have using System.Data using System.Configuration using etc.... why are they not all lumped into one 'using'? In other words, is there a best way to use project classes with 'using' meaning
14
5808
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the SQL DATABASE, probably by the click of a button. Is this possible? & what is the BEST APPROACH for doing this? & also if any links are there do tell those to me too coz I have no idea how to go about doing it.
8
2417
by: acb | last post by:
Hi, I wrote a DLL Component (using Visual Studio 2005) and managed to include it into a C# Console application. I am now trying to include this component into a Web project. I copy the DLL into the bin directory but am not able to progress. Can anyone please guide me to an online tutorial on the subject. Thanks,
0
2210
by: Metal2You | last post by:
I'm working on an ASP.NET 2.0 application in Visual Studio 2005 that accesses a Sybase database back end. We're using Sybase SQL Anywhere 9.0.2.3228. I have installed and registered the Sybase .NET 2.0 DataProvider (iAnywhere.Data.AsaClient.dll) into the GAC so it can be used in the ProviderName property of a SQLDataSource and loads properly at run time. The application I'm writing is a bit more complex than the example I'm about to...
10
1977
by: mg | last post by:
I'm migrating from VB6 and have a question about using 'Using' and the best way to use it. Here is a example of a small bit of code: dbConx("open") Using CN Dim CMD As New OleDbCommand(sSQL, CN) Dim DR As OleDbDataReader = CMD.ExecuteReader()
0
2579
by: Eugene Anthony | last post by:
The problem with my coding is that despite removing the records stored in the array list, the rptPages repeater control is still visible. The rptPages repeater control displayes the navigation link (1,2,3 so on). The code can be found in SubscriptionCart.aspx.cs. Default.aspx ------------
3
8310
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0 build with these methods, will appear to encrypt and decrypt, but the resulting decrypted file will be corrupted. I tried encrypting a .bmp file and then decrypting, the resulting decrypted file under .NET 2.0 is garbage, the .NET 1.1 build works...
6
5178
by: =?Utf-8?B?U2hhd24gU2VzbmE=?= | last post by:
Greetings! I was researching AJAX to provide a solution to displaying status messages while a long process executed. I found several examples online and was able to use their code to get a quick application working. However, when attempting to implement the solution, the AJAX calls weren't updating the screen like the examples were and seemed not to fire until after the long running process had completed. I found the only real...
0
9790
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10524
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7741
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6948
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5779
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4409
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3074
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.