Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Memory Leak ?

Memory Leak ?

Scheduled Pinned Locked Moved C#
performancequestion
13 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M musefan

    I dont think so, but not sure. Thou using image.fromfile() makes that files readonly and can be a pain when doing any deleting functions. i usually find it best to create the image from a stream

    My opinion is... If someone has already posted an answer, dont post the SAME answer

    X Offline
    X Offline
    Xmen Real
    wrote on last edited by
    #3

    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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

    M 1 Reply Last reply
    0
    • X Xmen Real

      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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

      M Offline
      M Offline
      musefan
      wrote on last edited by
      #4

      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

      T X 2 Replies Last reply
      0
      • M musefan

        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

        T Offline
        T Offline
        Tom Deketelaere
        wrote on last edited by
        #5

        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.

        M 1 Reply Last reply
        0
        • M musefan

          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

          X Offline
          X Offline
          Xmen Real
          wrote on last edited by
          #6

          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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

          M 1 Reply Last reply
          0
          • T Tom Deketelaere

            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.

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #7

            Thank you for the good, simple explaination of what i was trying to get at :)

            My opinion is... If someone has already posted an answer, dont post the SAME answer

            1 Reply Last reply
            0
            • X Xmen Real

              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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

              R Offline
              R Offline
              Rob Philpott
              wrote on last edited by
              #8

              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.

              M 1 Reply Last reply
              0
              • X Xmen Real

                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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                M Offline
                M Offline
                musefan
                wrote on last edited by
                #9

                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

                X 1 Reply Last reply
                0
                • R Rob Philpott

                  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.

                  M Offline
                  M Offline
                  musefan
                  wrote on last edited by
                  #10

                  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

                  X 1 Reply Last reply
                  0
                  • M musefan

                    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

                    X Offline
                    X Offline
                    Xmen Real
                    wrote on last edited by
                    #11

                    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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                    1 Reply Last reply
                    0
                    • M musefan

                      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

                      X Offline
                      X Offline
                      Xmen Real
                      wrote on last edited by
                      #12

                      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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                      1 Reply Last reply
                      0
                      • X Xmen Real

                        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%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i’TV.C\y<pŠjxsg-b$f4ia> -------------------------------------------------------- 128 bit encrypted signature, crack if you can

                        M Offline
                        M Offline
                        MadArtSoft
                        wrote on last edited by
                        #13

                        Try use Using keyword. It will dispose object. Read more in MSDN about Using keyword.

                        C# controls, .Net components. Help Desk Software

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups