Все вопросы: [dispose]

124 вопросов

похожие теги: disposabledisposingresource-disposal
1
голосов
1ответов
946 просмотров

Am I responsible for Disposing a BackgroundImage?

I have a windows form where I set the BackgroundImage property to a custom bitmap image. private Image MakeCustomBackground() { Bitmap result = new Bitmap(100, 100); using(Graphics canvas = Graphics.FromImage(result)) { // draw the custom image } return result; } ...

6
голосов
4ответов
3277 просмотров

Purpose of Dispose calling Dispose(IsDisposing) pattern in C#?

Here is code from MSDN. I don't understand why the work isn't just done in the regular Dispose() method here. What is the purpose of having the Dispose(bool) method? Who would ever call Dispose(false) here? public void Dispose() { Dispose(true); // Use SupressFinalize in case a subc...

3
голосов
2ответов
808 просмотров

Event Sender Gets Disposed In Client's Event Handler Code

I'm facing the following situation (C#/.Net here, but I think it's a general problem): Some of our object types (which are collections) are disposable types (IDisposable in C#, which allows clients to explicitly tell an object 'you are not needed anymore, free all of your resources') These coll...

5
голосов
5ответов
4487 просмотров

Do I need to call Graphics.Dispose()?

In a VB.NET program I'm creating a new bitmap image, I then call Graphics.FromImage to get a Graphics object to draw on the bitmap. The image is then displayed to the user. All the code samples I've seen always call .Dispose() on Bitmaps and Graphics objects, but is there any need to do that whe...

5
голосов
1ответов
622 просмотров

Does a wrapper class calling a COM component through C# need to implement the Dispose pattern?

I have a class written in c# which is acting as a wrapper around a COM component. The COM component is early bound and the RCW has been generated by Visual Studio. Should I implement a dispose pattern in my wrapper class to clean up the COM reference, or should I just let the GC handle it, as it ...

21
голосов
4ответов
22688 просмотров

Proper cleanup of WPF user controls

I am relatively new to WPF, and some things with it are quite foreign to me. For one, unlike Windows Forms, the WPF control hierarchy does not support IDisposable. In Windows Forms, if a user control used any managed resources, it was very easy to clean up the resources by overriding the Dispose ...

0
голосов
6ответов
120 просмотров

Strange GDI+ behaviour

I have made a method to CompressImageSize according to Image quality. The code for it is public static Image CompressImage(string imagePath, long quality) { Image srcImg = LoadImage(imagePath); //Image srcImg = Image.FromFile(imagePath); EncoderParameters parameters = new EncoderPar...

8
голосов
1ответов
8175 просмотров

How to dispose a Writeable Bitmap? (WPF)

Some time ago i posted a question related to a WriteableBitmap memory leak, and though I received wonderful tips related to the problem, I still think there is a serious bug / (mistake made by me) / (Confusion) / (some other thing) here. So, here is my problem again: Suppose we have a WPF appli...

1
голосов
3ответов
185 просмотров

Clearing up large fields from memory in long lived objects

.NET 3.5, I've got some classes which stores up to 1MB of strings. Even though I need the object for a really long time I don't need to store the string for a long time. How can I truly remove the string from memory without disposing the parent object. Is it a good practice to use "myString = ...

6
голосов
5ответов
8180 просмотров

Handling with temporary file stream

Say I want to define a TempFileStream class that creates a temporary file using Path.GetTempFileName() method. A temporary file must be deleted when TempFileStream's object is no longer needed, e.g. closed or disposed: class TempFileStream: FileStream { string m_TempFileName = Path.GetTempFile...

11
голосов
4ответов
23706 просмотров

How do I dispose all of the controls in a panel or form at ONCE??? c#

Possible Duplicate: Does Form.Dispose() call controls inside's Dispose()? is there a way to do this?

1
голосов
4ответов
2851 просмотров

C# Not Disposing controls like I told it to

I have a Panel control. And inside the panel users can add combobox's, textbox's labels etc and drag them around and stuff, and there's a Delete button on my form where if they click it, it will delete all controls inside that panel. BUT this code: foreach( Control control in panel.Controls ) { ...

3
голосов
3ответов
527 просмотров

Is re-using GDI+ objects bad practice? (or: How to use many nested using blocks without getting headaches?)

I'm currently writing a fairly complex paint method for a user control, involving a fair amount of drawing code. I know that all GDI+ resources need to be properly disposed so I wrap each of those in a using block. But when I noticed that I used three using blocks for three different SolidBrushe...

2
голосов
2ответов
1715 просмотров

Is mutex correctly implemented and how do I dispose it?

I am reviewing some code and one of the code analysis (fxCop) warnings has gotten me very confused. The code implements a few mutex's by creating variables at the start of the class, similar to this: private Mutex myMutex = new Mutex(); fxCop is popping up with a message saying that I must imp...

4
голосов
2ответов
13807 просмотров

Properly disposing of class with thread

I have a fairly complex multi-threaded Windows service working, but I can't figure out how to clean up correctly. Below is some [pseudo] code to show what I have. The actual code is much more complex, probably too much to copy/paste here. Basically, I have a class Request that creates a thread...

0
голосов
1ответов
1353 просмотров

SPWeb disposing himself and causing exception

When trying to use SPWeb.GetSiteData(SPSiteDataQuery) (Trying to bind some data to SPGridView), it throws me an TargetInvocationException with a following stacktrace: Exception at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodA...

0
голосов
2ответов
971 просмотров

Can't release Excel COM object in .NET

I have created a tool that imports an excel sheet. The excel COM object is created during the lifetime of the app. I have applied the MVP pattern to my tool so that VIEW and Presenter are seperating the UI and logic. The vIEW that is a WinForm is having a Dispose() method due inheritance from Fr...

5
голосов
3ответов
1042 просмотров

When do I need to manage managed resources?

I have been looking at the standard Dispose pattern and I'm just wondering what I need to write to free managed resources? If these resources are 'managed' already then surely I shouldn't need to do anything. If that's the case, and my class doesn't hold any unmanaged resources (hence no need fo...

4
голосов
5ответов
11389 просмотров

VB.NET Memory Management

Update: I probably confused memory usage issues with the UI sharing same thread as the processing (as pointed out by MusiGenesis below). However regarding the Memory usage. I am still not able to find VB.net specific syntax, although people have pointed out some great .Net and C# information be...

7
голосов
5ответов
5243 просмотров

When would dispose method not get called?

I was reading this article the other day and was wondering why there was a Finalizer along with the Dispose method. I read here on SO as to why you might want to add Dispose to the Finalizer. My curiousity is, when would the Finalizer be called over the Dispose method itself? Is there a code e...

18
голосов
2ответов
3271 просмотров

Entity Framework - How should I instance my "Entities" object

I'm a total newbie at Entity Framework and ASP.Net MVC, having learned mostly from tutorials, without having a deep understanding of either. (I do have experience on .Net 2.0, ADO.Net and WebForms) My current doubt comes from the way I'm instancing my Entities objects. Basically I'm doing this ...

2
голосов
3ответов
952 просмотров

Is this a legitimate alternative to the "traditional" dispose pattern for class hierarchies?

I am not a fan of boilerplate code: copy-paste reuse is potentially error-prone. Even if you use code snippets or smart templates, there is no guarantee the other developer did, which means there's no guarantee they did it right. And, if you have to see the code, you have to understand it and/or ...

5
голосов
3ответов
5953 просмотров

Will using a SPListItemCollection returned from a function reopen the SPWeb?

After reading Stefan Gossner's post about disposing objects and this question about Cross method dispose patterns, I found that I was guilty of accidentally reopening some SPWebs. I know in Stefan Gossner's post he mentions you should dispose of an SPWeb after you are finished with any child obje...

4
голосов
2ответов
1671 просмотров

When exposing IQueryable when does DataContext get disposed?

As seems to be popular at the moment, if you implement a repository as simply IQueryable<T> FetchAll<T>(); using LINQ to SQL, then the repository must set up a DataContext which remains available outside of the repository. So my question is, How does the DataContext get Disposed? ...

1
голосов
2ответов
270 просмотров

VB/C#: Placing disposible objects in global scope: Is this okay?

As an optimization, I decided to put an object I frequently need - an SDL surface with a prerendered image of the entire level (called S_AreaBMP) - at global scope. Now it doesn't have to be created and destroyed in the DrawScreen function every frame. I only need to dispose and change it when a ...

1
голосов
1ответов
167 просмотров

Disposing a control by calling its own BeginInvoke()

Disposing a control from by calling its own BeginInvoke() is a good idea or bad idea? Or shall I use the parent control or something like that to accomplish this task? I'm using Invoke because I'm accessing the control form another thread.

4
голосов
1ответов
468 просмотров

Cross Method Dispose Patterns in SharePoint

I've written a class that does various modification to the contents of a SharePoint site. Inside that class, I've implemented a lazy resolved property private SPWeb rootSite { get { if ( _site == null ) { SPSite site = new SPSite( ...

3
голосов
1ответов
145 просмотров

Why doesn't parent object fail with a previously disposed child object?

Potentially embarrassing question, but there is obviously something I'm missing that I want/need to know. I expect the following code to create a new table row with new cells to be rendered later. And that's what it does ... as you would expect. using (TableRow tr = new TableRow()) { using...

1
голосов
1ответов
1260 просмотров

How do I dispose of a VB6 COM object i'm using via an interop assembly from IronPython?

I'm using a third party COM component by means of a .NET interop assembly in IronPython, as seen here: How can I use a VB6 COM 'reference' in IronPython? My experience in this area has been great, I'm very impressed by the amount of stuff that works seamlessly... except one thing. The 3rd party...

1
голосов
1ответов
1222 просмотров

What are the effects of failing to close/dispose Powershell Runspace objects before process termination?

Given an application that maintains a singleton instance of a Runspace object (from System.Management.Automation.Runspaces) for the lifetime of the application, what are the potential side effects of failing to dispose of the Runspace before the application is terminated? The design rationale I ...