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. New,delete operator

New,delete operator

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelptutorial
4 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.
  • A Offline
    A Offline
    Anu_Bala
    wrote on last edited by
    #1

    Hi, I use the following coe in my applcation.and i found memory leak in that. MyFunction() { char *czval; czVal = new char[100]; memset(czVal,0,100); ..... ..... } But i failed to delete the memory allocated. I use delete [] czval in OnDestroy it shows thw error czVal undeclared identifier and also delete is used for pointer only. Whats my mistake. I use new operator in my local function where i have to delete that. And also i need tutorial for this new and delete.Because i have lot og memory leaks in my applicatin.I dont know the proper usage of new and delete operator.

    Anu

    S 1 Reply Last reply
    0
    • A Anu_Bala

      Hi, I use the following coe in my applcation.and i found memory leak in that. MyFunction() { char *czval; czVal = new char[100]; memset(czVal,0,100); ..... ..... } But i failed to delete the memory allocated. I use delete [] czval in OnDestroy it shows thw error czVal undeclared identifier and also delete is used for pointer only. Whats my mistake. I use new operator in my local function where i have to delete that. And also i need tutorial for this new and delete.Because i have lot og memory leaks in my applicatin.I dont know the proper usage of new and delete operator.

      Anu

      S Offline
      S Offline
      sudhir marni
      wrote on last edited by
      #2

      Make czval to global. Use delete[] czval in destructor / OnDestroy.

      A 1 Reply Last reply
      0
      • S sudhir marni

        Make czval to global. Use delete[] czval in destructor / OnDestroy.

        A Offline
        A Offline
        Anu_Bala
        wrote on last edited by
        #3

        I have doubt that when this OnDestroy() get called. Whether we can give breakpoint in OnDestroy() and check that. Because when i ahve breakpoint in OnDestroy in my view class,the control didnot go to the breakpoint. I dont know why?

        Anu

        S 1 Reply Last reply
        0
        • A Anu_Bala

          I have doubt that when this OnDestroy() get called. Whether we can give breakpoint in OnDestroy() and check that. Because when i ahve breakpoint in OnDestroy in my view class,the control didnot go to the breakpoint. I dont know why?

          Anu

          S Offline
          S Offline
          sudhir marni
          wrote on last edited by
          #4

          When the application is exited, CView::OnDestroy() will be invoked. So u can place the delete statement there.

          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