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 / C++ / MFC
  4. Please help! the way using SetBitmap, no memory leak?

Please help! the way using SetBitmap, no memory leak?

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
6 Posts 2 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.
  • T Offline
    T Offline
    twing
    wrote on last edited by
    #1

    when i use CStatic::SetBitmap, i don't know if memory leaks in my way. could u suggest me a good way out of leaking? Thank u very much! my way: CBitmap* pbmp = new CBitmap(); pbmp->LoadBitmap(someID); pstatic->SetBitmap(*pbmp); delete pbmp; //sometimes the line is ommitted Hello World!

    M 1 Reply Last reply
    0
    • T twing

      when i use CStatic::SetBitmap, i don't know if memory leaks in my way. could u suggest me a good way out of leaking? Thank u very much! my way: CBitmap* pbmp = new CBitmap(); pbmp->LoadBitmap(someID); pstatic->SetBitmap(*pbmp); delete pbmp; //sometimes the line is ommitted Hello World!

      M Offline
      M Offline
      Monty2
      wrote on last edited by
      #2

      if you allocate memory via new operator then you have to delete it via delete operator otherwise memory will be leaked in ur case delete pbmp would be done in OnDestroy pbmp should not be a local variable (define it in class) Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

      T 2 Replies Last reply
      0
      • M Monty2

        if you allocate memory via new operator then you have to delete it via delete operator otherwise memory will be leaked in ur case delete pbmp would be done in OnDestroy pbmp should not be a local variable (define it in class) Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

        T Offline
        T Offline
        twing
        wrote on last edited by
        #3

        I See. Thank u! Please use your head again. if u have another good way, please tell me immediately. Hello World!

        M 1 Reply Last reply
        0
        • M Monty2

          if you allocate memory via new operator then you have to delete it via delete operator otherwise memory will be leaked in ur case delete pbmp would be done in OnDestroy pbmp should not be a local variable (define it in class) Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

          T Offline
          T Offline
          twing
          wrote on last edited by
          #4

          i learn a little about smart points, but i don't know how to do. could u tell me? Thank u! Hello World!

          1 Reply Last reply
          0
          • T twing

            I See. Thank u! Please use your head again. if u have another good way, please tell me immediately. Hello World!

            M Offline
            M Offline
            Monty2
            wrote on last edited by
            #5

            why are you using new ? in class do CBitmap bmp; in Constructor do - bmp.LoadBitmap(MY_BMP); then in OnInitDialog pic.SetBitmap(&bmp); Done! Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

            T 1 Reply Last reply
            0
            • M Monty2

              why are you using new ? in class do CBitmap bmp; in Constructor do - bmp.LoadBitmap(MY_BMP); then in OnInitDialog pic.SetBitmap(&bmp); Done! Live as if your were to die tomorrow. Learn as if you were to live forever. -Mahatma Gandhi

              T Offline
              T Offline
              twing
              wrote on last edited by
              #6

              if so, how to do? i don't want to add many global variables. Could u have some useful way? Thank u! Hello World!

              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