{"id":6152,"date":"2014-04-13T04:35:08","date_gmt":"2014-04-13T04:35:08","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/outofmemory-exception-when-loading-lots-of-images-from-isolated-storage-collection-of-common-programming-errors-2\/"},"modified":"2014-04-13T04:35:08","modified_gmt":"2014-04-13T04:35:08","slug":"outofmemory-exception-when-loading-lots-of-images-from-isolated-storage-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/outofmemory-exception-when-loading-lots-of-images-from-isolated-storage-collection-of-common-programming-errors-2\/","title":{"rendered":"OutOfMemory Exception when loading lots of Images from Isolated storage-Collection of common programming errors"},"content":{"rendered":"<p><strong>EDIT:<\/strong> I keep getting OutOfMemoryException was unhandled, I think it&#8217;s how I am saving the image to isolated storage ,I think this is where I can solve my problem how do I reduce the size of the image before I save it? (added code where I save Image)<\/p>\n<p>I am opening images from Isolated storage sometimes over 100 images and I want to loop over them images but I get a <code>OutOfMemory Exception<\/code> when there is around 100 to 150 images loaded in to a storyboard. How can I handle this exception, I have already brought down the resolution of the images. How can I handle this exception and stop my app from crashing?<\/p>\n<p>I get the exception at this line here<\/p>\n<p><code>image.SetSource(isStoreTwo.OpenFile(projectFolder + \"\\\\MyImage\" + i + \".jpg\", FileMode.Open, FileAccess.Read));\/\/images from isolated storage<\/code><\/p>\n<p>here&#8217;s my code<\/p>\n<pre><code>private void OnLoaded(object sender, RoutedEventArgs e)\n    {\n\n\n        IsolatedStorageFile isStoreTwo = IsolatedStorageFile.GetUserStoreForApplication();\n\n\n\n        try\n        {\n            storyboard = new Storyboard\n            {\n                \/\/RepeatBehavior = RepeatBehavior.Forever\n            };\n\n            var animation = new ObjectAnimationUsingKeyFrames();\n\n            Storyboard.SetTarget(animation, projectImage);\n            Storyboard.SetTargetProperty(animation, new PropertyPath(\"Source\"));\n\n\n            storyboard.Children.Add(animation);\n            for (int i = 1; i  0)\n                    {\n                        targetStream.Write(readBuffer, 0, bytesRead);\n                    }\n\n                }\n\n            }\n\n\n\n\n        }\n        finally\n        {\n            \/\/ Close image stream\n            e.ImageStream.Close();\n        }\n\n    }\n<\/code><\/pre>\n<p>I would appreciate if you could help me thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>EDIT: I keep getting OutOfMemoryException was unhandled, I think it&#8217;s how I am saving the image to isolated storage ,I think this is where I can solve my problem how do I reduce the size of the image before I save it? (added code where I save Image) I am opening images from Isolated storage [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6152","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6152","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6152"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6152\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6152"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6152"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6152"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}