Can NUIs turn into a big snowball in the client's memory?

I’m developing my first NUI, and after finishing it, I was impressed by the number of elements I used in HTML/CSS/JS. And this is just one NUI out of many others the server will have. This specific NUI will only be used once per session by the player, and after that, it won’t be needed anymore.

So, I’d like to know if there’s a commonly used method among FiveM developers to completely unload a specific HTML/CSS/JS from memory. I don’t think simply setting it to hidden in the HTML is enough, as that would only hide it while the JS variables, CSS, and all elements would still remain in memory.

That means every time I set the NUI to true, even if it was for another NUI, all those previous resources would still be occupying the client’s memory, potentially turning the experience into a real nightmare.

Or am I just overthinking this?

Use react to destroy components when they aren’t needed.

But if your nui doesn’t have heavy logics to calculate and much images etc. it doesn’t matter too much.

If you want to overthink, remove your listeners when you done.

1 Like

I got it, destroy my EventListeners, destroy my HTML with react, I confess that I will have to learn react, but it’s for a good cause, in the case of this NUI mentioned, it has some resources that are a little heavy, yes, many Listeners, audio and other things, thanks for your answer!

Then you can start with react 19 it has built in memorization now. In past versions we must specify the memorized datas and use callbacks etc.

Would you want react boilerplate for nui to make a quick start?

1 Like

Yes a quick start is very good

You need to downgrade to tailwindcss3 if you want to use it.

1 Like