Memory Leak ?
-
musefan wrote:
Thou using image.fromfile() makes that files readonly and can be a pain when doing any deleting functions
what do you mean ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
I fount that having code such as Image image = Image.FromFile("C:\\pic.png"); meant that while that image was in memory, the file could not be deleted. Appears to be a reference to the actually file (or something) Maybe im mistaken but im pretty sure that was an issue
My opinion is... If someone has already posted an answer, dont post the SAME answer
-
I fount that having code such as Image image = Image.FromFile("C:\\pic.png"); meant that while that image was in memory, the file could not be deleted. Appears to be a reference to the actually file (or something) Maybe im mistaken but im pretty sure that was an issue
My opinion is... If someone has already posted an answer, dont post the SAME answer
musefan wrote:
Maybe im mistaken but im pretty sure that was an issue
No your not mistaken. Image.fromfile keeps the file locked until the object is disposed off. Ran into this when I was displaying an image in a picture box with this function. Ended up using the stream method like you said.
-
I fount that having code such as Image image = Image.FromFile("C:\\pic.png"); meant that while that image was in memory, the file could not be deleted. Appears to be a reference to the actually file (or something) Maybe im mistaken but im pretty sure that was an issue
My opinion is... If someone has already posted an answer, dont post the SAME answer
musefan wrote:
Appears to be a reference to the actually file
hehe no, I think it does the same thing as stream. Will you tell what was the thing that made you think that ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
musefan wrote:
Maybe im mistaken but im pretty sure that was an issue
No your not mistaken. Image.fromfile keeps the file locked until the object is disposed off. Ran into this when I was displaying an image in a picture box with this function. Ended up using the stream method like you said.
-
will this code leak the memory :
public class ABC
{
static Image aimage1;
static Image aimage2;
static Image aimage3;public static Image AImage1
{
get{ return aimage1;}
set{ aimage1 = value;}
}public static Image AImage2
{
get{ return aimage2;}
set{ aimage2 = value;}
}public static Image AImage3
{
get{ return aimage3;}
set{ aimage3 = value;}
}public static void Load()
{
AImage1 = Image.FromFile("C:\a.png");
AImage2 = Image.FromFile("C:\b.png");
AImage3 = Image.FromFile("C:\c.png");
}
}TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
No it won't leak as such. You have to try pretty hard to get .NET to leak properly. Image is disposable though, so you might want to dispose of images when you're done with them otherwise they might hang around longer than you want. (that'd release the file too).
Regards, Rob Philpott.
-
musefan wrote:
Appears to be a reference to the actually file
hehe no, I think it does the same thing as stream. Will you tell what was the thing that made you think that ?
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
No it won't leak as such. You have to try pretty hard to get .NET to leak properly. Image is disposable though, so you might want to dispose of images when you're done with them otherwise they might hang around longer than you want. (that'd release the file too).
Regards, Rob Philpott.
yeah i went down the dispose route at first when using .FromFile() but found it more hassle then creating one function that returns an Image from a stream by passing the filepath
My opinion is... If someone has already posted an answer, dont post the SAME answer
-
I found: using .FromFile() causes problems and using .FromStream() did not cause problems what more can i say, i didnt need to look into it anymore
My opinion is... If someone has already posted an answer, dont post the SAME answer
okay, see that was just a little part of my class. Actually im reading the images like this
BL = new Bitmap(new MemoryStream(tmp_br.ReadBytes(tmp_br.ReadInt32())));
Since i wrote that code(in first post) in CodeProject, so i thought to write Image.FromFile()
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
yeah i went down the dispose route at first when using .FromFile() but found it more hassle then creating one function that returns an Image from a stream by passing the filepath
My opinion is... If someone has already posted an answer, dont post the SAME answer
yes :) http://www.codeproject.com/script/Forums/View.aspx?fid=1649&msg=2912374
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
-
will this code leak the memory :
public class ABC
{
static Image aimage1;
static Image aimage2;
static Image aimage3;public static Image AImage1
{
get{ return aimage1;}
set{ aimage1 = value;}
}public static Image AImage2
{
get{ return aimage2;}
set{ aimage2 = value;}
}public static Image AImage3
{
get{ return aimage3;}
set{ aimage3 = value;}
}public static void Load()
{
AImage1 = Image.FromFile("C:\a.png");
AImage2 = Image.FromFile("C:\b.png");
AImage3 = Image.FromFile("C:\c.png");
}
}TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L %^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2 W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN% Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can
Try use Using keyword. It will dispose object. Read more in MSDN about Using keyword.