Comments (5)
Also, the remarks regarding keeping the stream open are valid all the way back
to the 2.0 framework.
http://msdn.microsoft.com/en-us/library/93z9ee4x(v=vs.80).aspx
Original comment by [email protected]
on 21 Dec 2012 at 9:51
from exiflibrary.
This issue was closed by revision r98.
Original comment by oozcitak
on 21 Dec 2012 at 10:02
- Changed state: Fixed
from exiflibrary.
Thanks for the detailed bug report. I fixed it as you suggested. However, a
quick test shows that the source stream is not automatically disposed when the
Image is disposed. It gets disposed during garbage collection when the stream
finalizer is called. Here is the test code:
public class XStream : System.IO.FileStream
{
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Console.WriteLine("Stream disposed");
}
public XStream(string filename)
: base(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read)
{
;
}
~XStream()
{
Console.WriteLine("Stream finalizer called");
}
}
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
XStream xs=new XStream(@"C:\test.jpg");
using (System.Drawing.Image img = System.Drawing.Image.FromStream(xs))
{
Console.WriteLine("Image created");
}
Console.WriteLine("Exiting");
}
}
I get the following output:
Image created
Exiting
The thread 0x1748 has exited with code 0 (0x0).
Stream finalizer called
Stream disposed
Original comment by oozcitak
on 21 Dec 2012 at 10:27
from exiflibrary.
This is probably not a big deal though; since we have a MemoryStream.
Original comment by oozcitak
on 21 Dec 2012 at 10:29
from exiflibrary.
I Guess you could dispose the stream if you managed the full life-time of the
Image but as you're an API and you're passing the image back to client code you
can't know when the lifetime of that object.
I've just had a look through Image.FromStream and it doesn't seem to track the
Stream object within the framework. It wraps it in a GPStream and calls into
the native gdipluss.dll . The way that the stream is (not) managed and therefor
finalized by the GC must be (i guess) by design.
As a side note, the image itself is IDisposible, so that should be disposed
appropriately which would remove the (last?) reference to the stream, allowing
it to be collected.
Thanks for the quick fix.
Original comment by [email protected]
on 21 Dec 2012 at 10:39
from exiflibrary.
Related Issues (20)
- Altitude tags HOT 1
- Cannot write EXIF HOT 10
- Method not found: Copy System.Array. HOT 7
- Problem saving and reading Windows related tags (e.g. Windows title) HOT 6
- Demo Project Crash HOT 2
- Cannot read large files HOT 1
- Tiff files are corrupted HOT 3
- Exception when reading file with dates set by the camera to Unknown HOT 3
- MathEx.UFraction32 from double endless loop HOT 1
- Can not clear properties HOT 2
- Library hang reading certain JPG files HOT 3
- ASCII Conversion HOT 9
- Files with 2 APP1 sections HOT 3
- Reserve more place for tag modifications
- Markernotes
- Removing GPS Data From JPEG Images Written with the Library
- Error (Jpeg not Opened)
- Question on recompression HOT 2
- Cannot Save Tiff Properties HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from exiflibrary.