Explicit data freeing in custom C++ runtime

Discuss issues pertaining to the various game/web runtimes of Creature here.
Post Reply
tete
Posts: 1
Joined: Fri Oct 14, 2022 8:57 pm

Explicit data freeing in custom C++ runtime

Post by tete » Fri Oct 14, 2022 9:17 pm

I'm trying to use a custom C++ engine with glut.
How can I free/delete data?

for example,
https://www.kestrelmoon.com/creaturedoc ... times.html

CreatureModule::CreatureLoadDataPacket json_data;
CreatureModule::LoadCreatureJSONData(filename, json_data);

auto cur_creature = std::shared_ptr<CreatureModule::Creature>(new CreatureModule::Creature(json_data));

creature_manager = new CreatureModule::CreatureManager(cur_creature);
creature_manager->CreateAnimation(json_data, "default");
creature_manager->CreateAnimation(json_data, "second");

above case,
how can I free cur_creature, etc?

delete cur_creature;
?? :?:

I'm thinking about how to load and delete various JSON data. :)

chong
Posts: 1178
Joined: Thu Feb 19, 2015 2:21 am

Re: Explicit data freeing in custom C++ runtime

Post by chong » Sun Oct 16, 2022 12:00 pm

Hello,

A shared_ptr will free itself once its reference count drops to 0.
You can learn more about it here:
https://www.oreilly.com/library/view/ef ... /ch04.html

Thanks

Post Reply