Code Monkey home page Code Monkey logo

Comments (1)

tfriedel6 avatar tfriedel6 commented on July 3, 2024

This one is unfortunately (probably) hard to avoid, at least I can't think of a good way to avoid it.

The way this works is that the DrawImage function will (when using OpenGL) allocate a texture and load the image into it. To delete the texture, the Image type actually has a Delete function on it, but as a safety catch there is also a finalizer so that the texture will be deleted if the garbage collector clears the image.

This is not ideal, but my reasoning was that it makes it really easy to just call DrawImage with an image, and you don't have to worry about anything more in most cases. But in this kind of case it does cause a lot of memory use.

What you can also do is something like this:

var cvimg *canvas.Image
if cvimg == nil {
	cvimg, _ = cv.LoadImage(img)
} else {
	cvimg.Replace(img)
}

The Replace function will actually replace the texture and should not increase the memory usage.

Hope that helps, but I'm also open to suggestions for how to do this in a better way.

from canvas.

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.