Been running a modified QBCore setup with some inventory stacking optimizations I wrote, but hitting a wall with memory management. After doing around 15-20 consecutive merge/split operations on items with the same name but different metadata, the client starts chugging hard and memory usage shoots up 50-100MB per session.
F8 console is spamming garbage collection warnings, and the inventory UI becomes completely unresponsive after about 30 stack operations. Profiler shows orphaned table references piling up in my inventory.lua stacking functions, specifically around line 447-489 in the client functions file.
Reproduction is straightforward - just run this in a loop:
for i = 1, 25 do TriggerEvent('inventory:client:stackItems', 'slot1', 'slot2', 5); Wait(100); end
After 20+ iterations, memory usage spikes dramatically while the inventory function holds references to all previous temporary stack objects. Event listeners are also accumulating without cleanup during merge operations, and database queries are somehow multiplying exponentially instead of batching properly.
Anyone dealt with similar reference issues in QBCore inventory systems? My knowledge stops at basic Lua memory concepts - not sure where the circular references are happening.
ToxicGamer · 31/08/2026
Your description matches classic reference retention patterns, but I need to verify something about your stacking logic. Are you creating new temporary tables or objects each time you process a stack operation, or reusing existing ones? The fact that you're seeing exponential query growth suggests you might have listeners or callbacks piling up with each operation rather than cleaning up after themselves. Check if your stackItems event handler is registering new event listeners or creating persistent references to temporary data structures that don't get cleared between operations.
ApexPredator · 31/08/2026
Sign in to reply.