Is having destroy function in every OOP object good practice?

Soo is it better to have one library to clear every type of OOP object, or have a destroy function inside every class? i want to know what is more efficient

Every OOP object should have a :Destroy() function, if necessary. Though using library functions to make destroying objects easier is a very good idea if you have a lot of objects.

1 Like

I’m worried that if i have one destroy function in every class that is specific to clear it 100% it will lag the game or make code inefficient, is this true? because using one library to clear stuff made it pretty much basic stuff and i sometimes needed to rewrite this library for more and more objects

1 Like

You don’t have to worry about it unless you’re working with data heavy objects, and even then you can slowly delete them in the background to eliminate lag.

1 Like

Soo the only possible problem is that if i use destroy function it will lag the game due to too much data being removed at the same time?

1 Like

Yeah. And even then you can use some methods to run the deletion in the background slowly to remove lag.

2 Likes

yk, i was scared that having a lot of code in modules, for example if i have 20 classes i have 20 different destroy functions for each of them, will make code look bad and overall will make it less performant, thx for explaining

2 Likes