Giter Club home page Giter Club logo

Comments (2)

robik75 avatar robik75 commented on September 3, 2024

d_zeros = h_zeros; /// will create memory leak

That isn't necessarily true - it depends on what you consider to be a memory leak.

This implicit conversion will create a new CudaDeviceVariable and assign it to the d_zeros variable. The old CudaDeviceVariable object will not be referenced anymore and the garbage collector will be free to collect it and run the finalizer at some later point in time - that finalizer will free the GPU memory.

CudaDeviceVariable implements the IDisposable interface but you do not use it in your example... that is your fault, not a problem with managedcuda.

from managedcuda.

kunzmi avatar kunzmi commented on September 3, 2024

As with any class that implements the IDiposable interface, it is the programmers responsibility to make sure to call Dispose() when the object isn't needed anymore. If you lose the reference to your object by overwriting it with other references, this is then a not properly handled IDisposable-object...

When implementing the implicit converters I was aware of exactly this risk, but the comfort that one gains is definitively worse it, isn't it?

@robik75 : the finalizer won't actually succeed to free the memory, as garbage collector runs on its own thread without a CudaContext assigned. The finalizer is not supposed to throw an exception, why this won't be seen until you actually run out of memory. But this problem exists for many IDisposable classes, that, if not handled correctly, unmanaged resources won't be freed.

BTW, if you run managedCuda in the debug version, it puts out warnings on the debug-console if Dispose() wasn't called by the user on some object...

from managedcuda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.