![]() If you don't find any reference to your stream in the memory snapshot then its been collected and memory is ready for reuse. In either case you can force a memory snapshot after the first click and look who is still keeping references to the stream. The VS diagnostic tool should report the cleanup immediately after the first click I think, unless it is also looking at process memory usage and not managed memory, but then it would be a VS tooling issue and not a. Eventually the heuristics will hand it back though if its not needed. NET runtime won't release GC'ed memory immediately to the OS in case it can reuse it for more allcoations. No I don't see anything obvious, unless you look at external measurements like process memory usage. MSDN forum reference link (for more details): Note: Disable the Prefer-32 bit in the Application Can you please suggest me how to release the total memory held by the resources? When tried to call the Garbage collection as in the below code snippet, I could see only 5 MB is reduced and the memory still stays at 155 MB. When test the memory in Visual Studio Diagnostic tool, I could see that the memory held by the resources is not released even after cleared and the memory stays at 160 MB. private void button_Click(object sender,RoutedEventArgs e) I wrote a button click event and cleared all the resources properly in the event handler as in the below code snippet. When the main page is loaded, I noted down the memory (using Visual Studio Diagnostic tool) is raised to 160 MB. Private void MainWindow_Loaded(object sender,RoutedEventArgs e) The link in Thorsten's posts verifies the validity of my post in this thread.I created a WPF application with byte array, memory stream and BitmapImage when a main page is loaded as in the below snippet. "If Yes, then what is the correct approach." "Is it really possible to get image information without loading into memory?" Yes as indicated in my post. Is it really possible to get image information without loading into memory? If Yes, then what is the correct approach.** Label3.Text = (Convert.ToInt32(Label2.Text) - originalMemory).ToString() + ", elapsed Time = " + sw.ElapsedMilliseconds.ToString() Ībove analysis adding created a doubt. Label2.Text = GC.GetTotalMemory(false).ToString() Using (FileStream fs = new FileStream(imagePhysicalPath + imgLoc, FileMode.Open, FileAccess.Read)) Code Block 2 - Start :: Load image by using "Image.FromStream" method. using ( image = (imagePhysicalPath + imgLoc)) Code Block 1 - Start :: Load image by using "Image.FromFile" method. String imagePhysicalPath = ConfigurationSettings.AppSettings Image1.ImageUrl = ConfigurationSettings.AppSettings + imgLoc Long originalMemory = GC.GetTotalMemory(false) Get memory size before loading image class. Private void button1_Click(object sender, EventArgs e)įor (int i = 0 i 10 MB, and even system stalled.Ĭode used : protected void Page_Load(object sender, EventArgs e) *png-pictures* - but it does *not affect* the faster execution time: //using JohnWein's example from the other thread _The data will be read "automatically" from the stream if you - for instance - display the image. To display the image you - of course - need to load the image data. You can use it to get the width height etc properties. Verify using the Stopwatch to time it and one of the other overloads. The Image.FromStream() overload that takes 3 parameters doesn't load the image if the 3rd parameter is false. Which one of these does not load the image into memory? Or is there any other way?ī0-4c84-45fa-ba87-ad8c15d497cb but it doesn't say anything about Image.FromFile() method. /// code here to get image height and width /// code here to get image height and width from "srcImg" object.Ģ.use using (FileStream fs = new FileStream("c:/a.jpg", FileMode.Open, FileAccess.Read)) What would be best way to get height and width of an image (can be any format), and without loading image into memory?
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |