[DiscordArchive] @here If I had this
[DiscordArchive] @here If I had this
Archived author: Claudiodfc • Posted: 2019-05-13T10:25:25.661000+00:00
Original source
@here If I had this
```
void UpdateAI(uint32 diff) override
{
(...)
Creature* fireSpirit = me->FindNearestCreature(NPC_FIRE_SPIRIT, 1.0f, true);
(...)
```
Every time that `fireSpirit` pointed to a different creature would I lose the last creature causing a leak? Or is it not dynamically allocated?
Archived author: Nix • Posted: 2019-05-13T10:38:53.407000+00:00
Original source
I'm pretty sure it points to the original creature pointer, so it should be fine.
Archived author: Claudiodfc • Posted: 2019-05-13T10:50:03.583000+00:00
Original source
Thanks
Archived author: Claudiodfc • Posted: 2019-05-13T10:50:23.299000+00:00
Original source
would you point them to nullptr after used <@171604048733011968>?
Archived author: Nix • Posted: 2019-05-13T10:56:06.793000+00:00
Original source
I would probably wrap it like this
```cpp
if (Creature* fireSpirit = me->FindNearestCreature(NPC_FIRE_SPIRIT, 1.0f, true);
{
}
```
Archived author: Nix • Posted: 2019-05-13T10:56:42.556000+00:00
Original source
This way the pointer only exists within the local scope, and you won't have to 'care' about it after you leave the scope.
Archived author: Claudiodfc • Posted: 2019-05-13T11:00:57.448000+00:00
Original source
neat, thanks