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. Managed C++/CLI
  4. Memory usage and dialogs

Memory usage and dialogs

Scheduled Pinned Locked Moved Managed C++/CLI
helpperformancetutorial
5 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.
  • D Offline
    D Offline
    dSolariuM
    wrote on last edited by
    #1

    Hi all, I have a problem with dialogs... After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases. I don't know how to free the extra memory that a dialog makes after closing it! please help me... Thank you.

    Every new thing you learn,Gives you a new personality.

    G M N L 4 Replies Last reply
    0
    • D dSolariuM

      Hi all, I have a problem with dialogs... After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases. I don't know how to free the extra memory that a dialog makes after closing it! please help me... Thank you.

      Every new thing you learn,Gives you a new personality.

      G Offline
      G Offline
      Giorgi Dalakishvili
      wrote on last edited by
      #2

      Call Dispose method of the form. Or just use using block and it will be automatically called for you.

      Giorgi Dalakishvili #region signature My Articles / My Latest Article[^] / My blog[^] #endregion

      1 Reply Last reply
      0
      • D dSolariuM

        Hi all, I have a problem with dialogs... After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases. I don't know how to free the extra memory that a dialog makes after closing it! please help me... Thank you.

        Every new thing you learn,Gives you a new personality.

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        Giorgi's reply is correct, but since this is a C++ board, I'll assume you're using C++/CLI... You should call Dispose on IDisposable-derived objects. More important than releasing memory is releasing unmanaged resources held by the object. In C++/CLI, these are the ways to get Dispose() called on an object (taken right from the docs):

        \*If an object created using stack semantics goes out of scope. For more information, see C++ Stack Semantics for Reference Types.
        \*If an exception is thrown during the object's construction.
        \*If the object is a member in an object whose destructor is running.
        \*If you call the delete Operator (C++) on a handle (^ (Handle to Object on Managed Heap)).
        \*If you explicitly call the destructor.
        

        Using delete is the most natural C++ way IMO...Here's an example:

        Form ^frm = gcnew Form();
        ...
        delete frm;  // calls Dispose() since Form is IDisposable!
        

        You're still not going to see all memory released using task manager. There will still be many managed objects that will be released when the GC gets around to it. Mark

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        1 Reply Last reply
        0
        • D dSolariuM

          Hi all, I have a problem with dialogs... After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases. I don't know how to free the extra memory that a dialog makes after closing it! please help me... Thank you.

          Every new thing you learn,Gives you a new personality.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Adding to other replies You can use Stack Semantics to automatically delete object when the scope ends. So don't use handle when creating object. Write like this

          Form2 frm;
          frm.ShowDialog();

          When variable goes out of scope, it's distructor will get called automatically.

          Navaneeth How to use google | Ask smart questions

          1 Reply Last reply
          0
          • D dSolariuM

            Hi all, I have a problem with dialogs... After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases. I don't know how to free the extra memory that a dialog makes after closing it! please help me... Thank you.

            Every new thing you learn,Gives you a new personality.

            L Offline
            L Offline
            led mike
            wrote on last edited by
            #5

            What everyone else said, plus:

            dSolariuM wrote:

            After using ShowDialog() method to show a dialog, memory usage (in Task manager) rises Up about 3 Mega bytes. But after closing that dialog only 1 mega byte of memory releases.

            What is going on in that dialog? If code in the dialog is allocating memory or resources then you are responsible for cleaning it up. Simply closing the dialog will NOT free any memory or resources that your code specifically allocates, including the dialog object itself if you allocated it on the heap.

            led mike

            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