Questions tagged [dispose]

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources

Microsoft.NET

The pattern for disposing an object, referred to as a dispose pattern, imposes order on the lifetime of an object. The dispose pattern is used only for objects that access unmanaged resources. This is because the garbage collector is very efficient at reclaiming unused managed objects.

A type's Dispose method should release all the resources that it owns. It should also release all resources owned by its base types by calling its parent type's Dispose method. The parent type's Dispose method should release all resources that it owns and in turn call its parent type's Dispose method, propagating this pattern through the hierarchy of base types.

Reference

1987 questions
0
votes
0 answers

Dispose Pattern Confusion

I'm unclear about what classes need to implement IDisposable. Obviously those with unmanaged resources, but what about those with member variables that are IDisposable? For example, if a class has a member variable that's a ManualResetEvent (which…
uncaged
  • 597
  • 1
  • 5
  • 17
0
votes
1 answer

Cannot access a disposed object Error when Call component two times in a row

In my project I have a component that displays a list of products in a specific group. public class ProductListIncategoryViewComponent : ViewComponent { private IProductRepository productRepository; public…
0
votes
1 answer

readonly object for unit testing is being disposed when using 'using'

I have an object that is used a bunch of times within the same unit test, and in other unit tests within the same class, that is defined as follows: private readonly Task successfulResponse = Task.FromResult( new…
Ahmad
  • 12,886
  • 30
  • 93
  • 146
0
votes
1 answer

Unable to Dispose Control (NotifyIcon)

In my homework application; I am required to create an application where I am also required to use a NotifyIcon. I'm facing a problem where I cannot understand why the Code never reaches the Dispose Event. I'm implementing "IDisposable"; (in order…
user12761381
0
votes
3 answers

flutter: error during use shared preference

I'm trying to use shared preference to keep user login and I put it in the splash screen and when I run the project this error has appeared: [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: setState() called after dispose():…
Mariam Younes
  • 389
  • 6
  • 29
0
votes
1 answer

Entity framework performance issue when instantiate and dispose model frequently

I create a new System.Data.Objects.ObjectContext (my EF model) every time a DAL method is called: Public void DoSomeDataManipulation() { using (MyModel myModel = new MyModel(connectionString)) …
Xaqron
  • 29,931
  • 42
  • 140
  • 205
0
votes
1 answer

Use Disposable objects inside Task

I'm developing a Web Application for process a large amount of data and create a .csv file with those items. So far, so good, but, it occored to me that it's not really fast this proccess, so I decide to make all those things in Task…
Guilherme Golfetto
  • 510
  • 2
  • 5
  • 25
0
votes
1 answer

How to Dispose subscriptions in a UserControl if you can change the VisualParent

I have a FooUserControl which subscribes on it's LoadedEvent. This UserControl can be placed else where on your gui (on any Window or inside of any Control). To avoid leaks, I have implemented some kind of disposing. The problem with this…
Dominic Jonas
  • 4,717
  • 1
  • 34
  • 77
0
votes
1 answer

releasing Jedis pool

In most examples including this Jedis example the Jedis pool is created in the try..catch parenthesis which I think disposes it: try(Jedis jedis = jedisPool.getResource()) { some code } For me this is not possible because I need to throw errors…
developerX
  • 33
  • 4
0
votes
0 answers

RxJava2: How to avoid InterruptibleException after a subscriber was disposed?

I have an observable: public Observable> getConversationListObservable() { return Observable.create(emitter -> { List conversations = networkApi.getConversations(); for (Conversation conversation…
isabsent
  • 3,683
  • 3
  • 25
  • 46
0
votes
1 answer

C# proper use of Dispose with SafeSocketHandle

Im aware of the dispose pattern and would like to properly dispose my Socket resource. In the documentation they recommend to use SafeHandles, but I'm not sure how exactly this works with System.Net.Socket. I discovered that the Socket class itself…
Josh
  • 287
  • 1
  • 8
0
votes
1 answer

How to release serial COM port from dll

I'm using .dll to in my code so i create object for that, in which .dll open the serial com port but after use it not release the comport. but in my application i want to open comport again but comport occupied by the .dll so it gives error. please…
Gaurav
  • 11
  • 1
0
votes
2 answers

Is IDisposable object disposed itself after RETURN from method?

Let's say, I have the following code: theIDisposableObject myMethod() { theIDisposableObject smth=new theIDisposableObject(); return smth; } void Main() { var A= myMethod(); ... A.Dispose(); } Do I do it correctly? i mean, is…
T.Todua
  • 53,146
  • 19
  • 236
  • 237
0
votes
1 answer

Dispose the thread and delete the file associated to that thread

I want to dispose the process thread and delete a file associated to that thread. So I am being able to dispose the thread but while deleting the file, it still says that the file is being is being used by the process. foreach (Match match in…
wax
  • 43
  • 5
0
votes
1 answer

How to delete clip-path mask from image object in canvas using fabricJS?

I am working in one image editing tool in which i need one functionality of image clipping mask. I am using fabric js latest version. I have put one toggle button for clip image into circle. and want to toggle it from circle to square(or other fix…
Mayur Kukadiya
  • 2,461
  • 1
  • 25
  • 58
1 2 3
99
100