sol2 icon indicating copy to clipboard operation
sol2 copied to clipboard

the example may be memory leak?

Open ImAlien opened this issue 1 year ago • 1 comments

I read the https://sol2.readthedocs.io/en/latest/tutorial/cxx-in-lua.html and try it; I set the player some memory and create a lot of players in my scripts player.h:

struct player {
public:
	int bullets;
	int speed;
	int memery[100000];

script:

for i = 2, 100000000 do
	p1 = player.new()
end
p1 = nil

my task manager show that the memory increase gradually

ImAlien avatar Jun 21 '23 10:06 ImAlien

I change the regesiter code

sol::constructors<player(), player(int), player(int, int)>());

to

"new", sol::factories(
			create
		)

create is defined this:

std::shared_ptr<player> create() {
	return std::make_shared<player>();
}

ImAlien avatar Jun 21 '23 10:06 ImAlien