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. Memory allocated out side of try and Delete in finally

Memory allocated out side of try and Delete in finally

Scheduled Pinned Locked Moved C / C++ / MFC
performancehelpquestion
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.
  • P Offline
    P Offline
    ptr_Electron
    wrote on last edited by
    #1

    I had a memory allocated out side a try block and I am trying to delete in finally? Should there be any issue with this. I am getting access violation while deleting

    char *heap = new char [50];
    try
    {

        ......
    

    }
    finally(...)
    {

    delete[] heap; // access violation
    }

    J 1 Reply Last reply
    0
    • P ptr_Electron

      I had a memory allocated out side a try block and I am trying to delete in finally? Should there be any issue with this. I am getting access violation while deleting

      char *heap = new char [50];
      try
      {

          ......
      

      }
      finally(...)
      {

      delete[] heap; // access violation
      }

      J Offline
      J Offline
      Jochen Arndt
      wrote on last edited by
      #2

      It should work when not modifying (which includes deleting) the heap pointer inside the try block. If you are not doing such (just comment the code inside the try block to check it), you should tell us which compiler you are using because finally is not defined by the C++ standard.

      P 1 Reply Last reply
      0
      • J Jochen Arndt

        It should work when not modifying (which includes deleting) the heap pointer inside the try block. If you are not doing such (just comment the code inside the try block to check it), you should tell us which compiler you are using because finally is not defined by the C++ standard.

        P Offline
        P Offline
        ptr_Electron
        wrote on last edited by
        #3

        I am using RAD Studio code gear

        J 1 Reply Last reply
        0
        • P ptr_Electron

          I am using RAD Studio code gear

          J Offline
          J Offline
          Jochen Arndt
          wrote on last edited by
          #4

          So it is the BCC compiler. According to the __finally (C++) - RAD Studio[^] it should be __try and __finally. When omitting the leading underscores the code should not even compile because try requires a catch and __try requires an __except or __finally. Is it still not working with the correct syntax and an empty __try block? Then you might ask this in a BCC specific forum like Recent Topics - Forum - Embarcadero Community[^].

          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