# \[Solved\] Debugging an apparent memory leak

**URL:** https://discourse.julialang.org/t/solved-debugging-an-apparent-memory-leak/1828
**Category:** General Usage
**Created:** [February 1, 2017, 8:34pm UTC](https://discourse.julialang.org/t/solved-debugging-an-apparent-memory-leak/1828 "2017-02-01T20:34:50Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Michael\_Eastwood](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/michael_eastwood/32/669_2.png) [@Michael\_Eastwood](https://discourse.julialang.org/u/Michael_Eastwood)
#### Post date: [February 9, 2017, 2:28am UTC](https://discourse.julialang.org/t/solved-debugging-an-apparent-memory-leak/1828/2 "2017-02-09T02:28:08Z")

</div>

Updating this thread now that I’ve figured out what the problem was. Hopefully this helps somebody coming from Google (hi!).

The problem is not at all related to the code structure I outlined in the previous post, but rather the details of the `long_computation` function are at fault.

Essentially I wrote a wrapper around a C++ library that does things like

```julia
type MyCxxType
    ptr :: Ptr{Void}
end

function MyCxxType()
    ptr = ccall( ... ) # new CxxType()
    output = MyCxxType(ptr)
    finalizer(output, delete)
    output
end

function delete(input::MyCxxType)
    ccall( ... ) # calls delete
end

```

The `ccall`s simply call `new` and `delete` for the corresponding type in C++.

I believe the problem here is similar to [https://github.com/JuliaLang/julia/issues/11698](https://github.com/JuliaLang/julia/issues/11698)

Essentially the Julia garbage collector doesn’t know how large `MyCxxType` really is (it thinks it’s just a pointer). Therefore it never feels any pressure to call the object’s finalizer and so nothing ever gets garbage collected. The solution is therefore to not do this. Write the wrapper in a way that you’re not storing `Ptr{Void}` as a field. It turns out that that was a mistake…

---

_[View the full topic](https://discourse.julialang.org/t/solved-debugging-an-apparent-memory-leak/1828)._
