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. Is this a genuine memory leak?

Is this a genuine memory leak?

Scheduled Pinned Locked Moved C / C++ / MFC
performancequestion
2 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.
  • G Offline
    G Offline
    Gavin Jerman
    wrote on last edited by
    #1

    BoundsChecker is reporting the following code as a memory leak: void foo() { _bstr_t bstrA; _bstr_t bstrB; bstrA = "Fred"; bstrB = "Wilma"; bstrB = bstrA.copy(); // this causes the leak // this fixes the leak - bstrB = bstrA } At first I thought it was a leak, then I decided it wasn't, now I can't decide! Is it, or isn't it :confused: Gavin

    T 1 Reply Last reply
    0
    • G Gavin Jerman

      BoundsChecker is reporting the following code as a memory leak: void foo() { _bstr_t bstrA; _bstr_t bstrB; bstrA = "Fred"; bstrB = "Wilma"; bstrB = bstrA.copy(); // this causes the leak // this fixes the leak - bstrB = bstrA } At first I thought it was a leak, then I decided it wasn't, now I can't decide! Is it, or isn't it :confused: Gavin

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      Yes, that will leak. "copy" will create a copy and then the assignment will create another copy since it can not assume that the original is free for ownership. bstrB = bstrA; bstrB .Attach (bstrA .copy ()); bstrB = bstrA .copy (false); These should all work just fine. But I don't do a lot of _bstr_t work. Tim Smith "Programmers are always surrounded by complexity; we can not avoid it... If our basic tool, the language in which we design and code our programs, is also complicated, the language itself becomes part of the problem rather that part of the solution." Hoare - 1980 ACM Turing Award Lecture

      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