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. Destroy CString instance?

Destroy CString instance?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 4 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.
  • O Offline
    O Offline
    Oliver123
    wrote on last edited by
    #1

    Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks. void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }

    C E J 3 Replies Last reply
    0
    • O Oliver123

      Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks. void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Oliver123 wrote:

      Is a separate CString textSub instance created each time the function executes?

      Of course. You don't need to clean it up, it's not a pointer, it will clean itself up ( calling it's own destructor )

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      1 Reply Last reply
      0
      • O Oliver123

        Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks. void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }

        E Offline
        E Offline
        Eytukan
        wrote on last edited by
        #3

        Unless you use a "new" operator explicitly,it gets cleaned up automatically once it looses it's scope (Once it returns back to the caller). If you had used "new" to instantiate the object,then you need to "delete" it mannualy.


        Dario: How is "directory" in French? (I mean a file system directory). John Simmons: "zee file holdaire thingie"

        1 Reply Last reply
        0
        • O Oliver123

          Suppose I have the following function which is executed many times in a program. Is a separate CString textSub instance created each time the function executes? Do I need to destroy the CString textSub at the end of the function? Or suppose it wasn't CString, but some other class? Thanks. void CNew1Dlg::OnBUTTONPick() { CString textSub; textSub.Format("%d %s", someNumber, someString); GetDlgItem(someEditBox)->SetWindowText(textSub); }

          J Offline
          J Offline
          Joan M
          wrote on last edited by
          #4

          Another important thing is: sometimes you'll need to call GetBuffer() or another function of that kind, if you do that, you must remember to call also ReleaseBuffer() just before exiting the scope of the CString variable. Hope this helps

          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