Closed chenxx08 closed 4 years ago
Indeed.
However, since re-creating multiple SDL windows is a very specific use case, we don't intend to fix this. A pull request is welcome!
@warrenseine I think we've made lots of memory improvements for some of our latest customer projects and the 3D player on minko.io. Are those changes available on dev ?
If Minko is not just for game, the case should be more common. I use it on the Android and iOS to view 3D model. User maybe repeatedly navigate to the 3D model view.
This problem should be caused by circular reference that is very common in this project. Do you have any suggestion to solve this problem. Thank you!
This problem should be caused by circular reference that is very common in this project. Do you have any suggestion to solve this problem. Thank you!
This is exactly the kind of things we fixed using std::weak_ptr
for example. @warrenseine ?
In that specific case, I think I know where the leak is. We keep the last allocated canvas in a static variable. See Canvas::defaultCanvas()
.
@promethe42 Changing this to a weak_ptr
should safely fix the issue. @chenxx08 Can you try and tell us if the leak goes away?
The problem still exsit. It's caused by circular reference. As shown in the following code.
//Canvas.hpp class Canvas: { ... std::shared_ptrinput::SDLMouse _mouse; ... }
//Canvas.cpp void Canvas::initializeInputs() { _mouse = input::SDLMouse::create(shared_from_this()); ... }
//Mouse.hpp
class Mouse
{
...
std::shared_ptr
//Mouse.cpp
Mouse::Mouse(std::shared_ptr
Touch, Joystick and some other class also have the same problem. Some class like Node fixed in Dev branch by use weak_ptr, some class still not use weak_ptr.
And some code like below may also cause circular reference.
_classField = someSignal.connect(std::bind(
&Class::someMethod,
std::dynamic_pointer_cast
It's can be modified like below: _classField = someSignal.connect(std::bind( &Class::someMethod, this, ... ));
Did you test the latest version on dev ?
The useCount is not zero, the canvas and other objects(sceneManager, root, etc.) didn't disposed. If I create the Minko window several times and then close in my program, memory usage will be more and more.
Sorry for my poor English.