dispose

Returning image created by Image.FromStream(Stream stream) Method

混江龙づ霸主 提交于 2019-12-23 07:13:20
问题 I have this function which returns an Image within the function the image is created using the Image.FromStream method According to MSDN: You must keep the stream open for the lifetime of the Image So I'm not closing the stream(if I do close the steam a GDI+ exception is thrown from the returned image object). My question is whether the stream will be closed/disposed when Image.Dispose() is called somewhere else on the returned Image public static Image GetImage(byte[] buffer, int offset, int

Entity Framework - Load Reference Keys after disposing entity object context

风流意气都作罢 提交于 2019-12-23 02:49:08
问题 I am using ASP.Net / WebForms / Entity Model / Framework 3.5 Here is my project's simple structure Forms > BLL > DAL ( uses entity model ) Here is my DAL's snippet public class MyDAL : IDisposable { private MyEntities db; public BaseDAL() { db = new MyEntities(); } public User GetUserByID(int userId) { try { IQueryable<User> objUser = null; objUser = from res in db.Users where res.UserId == userId select res; return objUser.FirstOrDefault(); } catch { throw; } } public void Dispose() { db

.NET - Why is disposing of standard output only allowed during unit tests?

你说的曾经没有我的故事 提交于 2019-12-23 02:36:27
问题 First of all, I want to point out that I do not really want to dispose of the standard output...I just want to know why I'm seeing the described behavior. I didn't write the bad code described. I'm using .NET 4 for the unit tests and .NET 3.5 for the code being tested. I'm using MSTest for .NET 4 as my testing framework. Recently I have been working with a library that was throwing errors due to the blunder of disposing of the standard error output. (See LibTiff.NET ReadDirectory is giving

Garbage Collector too slow when working with large images

独自空忆成欢 提交于 2019-12-22 22:20:55
问题 I am using Emgu OpenCV to grab images from a webcam and want to visualize them with WPF Image Control. So I need to convert the image from Mat to something compatible with Image control. So I took this class from the Emgu examples: public static class BitmapSourceConvert { /// <summary> /// Delete a GDI object /// </summary> /// <param name="o">The poniter to the GDI object to be deleted</param> /// <returns></returns> [DllImport("gdi32")] private static extern int DeleteObject(IntPtr o); ///

Do I win memory by explicitly disposing imageView.Image?

戏子无情 提交于 2019-12-22 17:35:24
问题 I have this code in my app: var newImage = // ... if (imageView.Image != null && imageView.Image != newImage) imageView.Image.Dispose (); imageView.Image = newImage; I have three related questions: Does it immediately release the memory occupied by the previous imageView.Image ? If it does, is there a cleaner solution? Does this have anything to do with NSAutoreleasePool ? 回答1: Does it immediately release the memory occupied by the previous imageView.Image? Not immediately but it should be

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

Custom dialog using JOptionPane API won't dispose

≡放荡痞女 提交于 2019-12-22 09:52:05
问题 I've been just playing with JOptionPane API to show a custom dialog and I've found a strange situation: when I choose either OK or Cancel option or press Esc key this dialog won't dispose as expected. The thing is, instead of using this single line to display a modal dialog: JOptionPane.showConfirmDialog( null , "The quick brown fox jumps over the lazy dog." , "New Dialog" , JOptionPane.OK_CANCEL_OPTION , JOptionPane.PLAIN_MESSAGE); I wanted to use the API, setting all the parameters one by

c# cannot access a disposed object

扶醉桌前 提交于 2019-12-22 04:43:31
问题 I am making an server/client application. I set server socket to listening, and set BeginAccept() method. And when I closed server socket (Socket.Close()) to turn off server, an exception thrown from BeginAccept() method's async callback method. I inspected exception, and I found the exception saying me this: Message "Cannot access a disposed object named "System.Net.Sockets.Socket". Object name: "System.Net.Sockets.Socket"." String In my opinion, this is just this: "The socket disposed when

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

Explain the mysterious world of IoC and automatic Dispose

允我心安 提交于 2019-12-22 00:52:40
问题 I'm ASP.NET MVC newbye and I'm learning and experimenting Enterprise design patterns: very interesting and helpful things indeed! But I keep missing something about the concept of disposing resources. To be more specific want to focus on the mechanism of controllerFactory which injects in the controller constructor an implementation of IFuncyRepository or IFuncyService or anyother kind of "resource" to be used in the controller (In my case I'm using StructureMap as IoC). My question is WHERE