idisposable

Memory release with IDisposable and without IDisposable

雨燕双飞 提交于 2019-12-22 10:42:41
问题 In my app I have a large object that's created every few seconds. I do with it some job and then I don't need it anymore. I saw in the task manager that the ram size goes up even if I don't have any reference to the object and it needs to be collected. After implementing IDisposable the ram goes down immediately. Why is this? I didn't do GC.Collect , I just released the object and told the GC it doesn't need to call the finalizer for my object. EDIT: Here is the code I use for my IDisposable

Dependency injection and life time of IDisposable objects

眉间皱痕 提交于 2019-12-22 08:17:22
问题 I am trying to develop a library using dependency injection approach (with Ninject) and I am having some kind of confusion likely because of my incorrect design. In summary, my design approach is A parent object has a common object. A parent object uses some variable number of child objects. All child objects should use the very same common object instance with their parent object Here is a simple model of my problem domain. interface IParent : IDisposable { void Operation(); } interface

Dispose StreamResourceInfo.Stream

蓝咒 提交于 2019-12-22 05:23:31
问题 I use StreamResourceInfo.Stream to get BitmapImage s from resources. Is it correct to Close and Dispose the stream after using it? I ask because in memory profiler, I get an error if I do so. Memory profiler says that a disposed instance has not been GCed. If I look on the web, I only can find this post to this topic. In this post, the responding person says, that it is meaninfull to dispose. However if I look at the circumstances and on the effect, I don't think that this is right. Does

Use of Process with using block [duplicate]

梦想与她 提交于 2019-12-22 03:44:28
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: What happens if I don't close a System.Diagnostics.Process in my C# console app? As System.Diagnostics.Process inherits from Component which implements IDisposable , should I always create a Process with a using block? For example, this...: using (var process = new Process()) { process.StartInfo.FileName = "some process.exe"; process.Start(); process.WaitForExit(); } ...instead of this: var process = new Process

Singleton with finalizer but not IDisposable

吃可爱长大的小学妹 提交于 2019-12-22 01:38:58
问题 This is what I understand about IDisposable and finalizers from "CLR via C#", "Effective C#" and other resources: IDisposable is for cleaning up managed and unmanaged resources deterministically. Classes that are responsible for unmanaged resources (e.g. file handles) should implement IDisposable and provide a finalizer to guarantee that they are cleaned up even if the client code does not call Dispose() on the instance. Classes that are responsible for managed resources only should never

Why is use better than using?

故事扮演 提交于 2019-12-22 01:37:42
问题 According to the last sentence on this MSDN page use is to be preferred over using . I've heard it elsewhere (this answer, for example). Why is this? I realize use was added later. But what's the difference? On the surface, using seems more useful because you can control when Dispose() is called, and you can explicitly ignore the bound value (e.g., (fun _ -> ...) ) if needed. 回答1: I think that the reason for preferring use is just that the syntax is simpler. Many other language constructs

Correct way to close WCF 4 channels effectively

怎甘沉沦 提交于 2019-12-21 03:46:11
问题 I am using the following ways to close the WCF 4 channels. Is this right way to do it? using (IService channel = CustomChannelFactory<IService>.CreateConfigurationChannel()) { channel.Open(); //do stuff }// channels disposes off?? 回答1: Although not strictly directed at the channel, you can do: ChannelFactory<IMyService> channelFactory = null; try { channelFactory = new ChannelFactory<IMyService>(); channelFactory.Open(); // Do work... channelFactory.Close(); } catch (CommunicationException) {

Correct way to close WCF 4 channels effectively

*爱你&永不变心* 提交于 2019-12-21 03:46:06
问题 I am using the following ways to close the WCF 4 channels. Is this right way to do it? using (IService channel = CustomChannelFactory<IService>.CreateConfigurationChannel()) { channel.Open(); //do stuff }// channels disposes off?? 回答1: Although not strictly directed at the channel, you can do: ChannelFactory<IMyService> channelFactory = null; try { channelFactory = new ChannelFactory<IMyService>(); channelFactory.Open(); // Do work... channelFactory.Close(); } catch (CommunicationException) {

How does LINQ defer execution when in a using statement

非 Y 不嫁゛ 提交于 2019-12-20 18:35:53
问题 Imagine I have the following: private IEnumerable MyFunc(parameter a) { using(MyDataContext dc = new MyDataContext) { return dc.tablename.Select(row => row.parameter == a); } } private void UsingFunc() { var result = MyFunc(new a()); foreach(var row in result) { //Do something } } According to the documentation the linq execution will defer till I actual enumerate the result, which occurs in the line at the foreach. However the using statement should force the object to be collected reliably

Code Analysis CA1063 fires when deriving from IDisposable and providing implementation in base class

和自甴很熟 提交于 2019-12-20 16:10:30
问题 I have some code that will trigger Code Analysis warning CA1063: CA1063 : Microsoft.Design : Remove IDisposable from the list of interfaces implemented by 'Functionality' and override the base class Dispose implementation instead. However, I'm not sure what I need to do to fix this warning. Briefly, I have an interface IFunctionality that derives from IDisposable . Class Functionality implements IFunctionality but derives from class Reusable to be able to reuse som code. Class Reusable also