local ScreenW, ScreenH = guiGetScreenSize() setTimer(function() ProcessMemory = getProcessMemoryStats() -- update process memory stats in every second to get the latest memory usage= ProcessMemory.streamingUsed = engineStreamingGetUsedMemory() ProcessMemory.streamingMax = engineStreamingGetMemorySize() DxStatus = dxGetStatus() end, 1000, 0) addEventHandler('onClientRender', root, function() -- draw process memory stats on the screen if not ProcessMemory then return end local FontHeight = dxGetFontHeight(1.5, 'default-bold') local FormatString = 'Virtual: %s/%s MB | Resident: %s/%s MB | Private: %s/%s MB | Shared: %s MB | Streaming %s/%s MB\nTextures %s MB | RenderTargets %s MB | Fonts %s MB | Total Video %s/%s MB' local StringToDraw = string.format( FormatString, math.floor(ProcessMemory.virtual / 1024 / 1024), (4 * 1024), math.floor(ProcessMemory.resident / 1024 / 1024), (3.5 * 1024), math.floor(ProcessMemory.private / 1024 / 1024), (3.5 * 1024), math.floor(ProcessMemory.shared / 1024 / 1024), math.floor(ProcessMemory.streamingUsed / 1024 / 1024), math.floor(ProcessMemory.streamingMax / 1024 / 1024), DxStatus.VideoMemoryUsedByTextures, DxStatus.VideoMemoryUsedByRenderTargets, DxStatus.VideoMemoryUsedByFonts, math.floor(DxStatus.VideoMemoryUsedByTextures + DxStatus.VideoMemoryUsedByRenderTargets + DxStatus.VideoMemoryUsedByFonts), math.floor(DxStatus.VideoMemoryFreeForMTA) ) dxDrawText(StringToDraw, 10, ScreenH - (FontHeight * 2) - 5 + 1, 0, 0, tocolor(0, 0, 0, 255), 1.5, 'default-bold', 'left', 'top') dxDrawText(StringToDraw, 10, ScreenH - (FontHeight * 2) - 5, 0, 0, tocolor(255, 255, 255, 255), 1.5, 'default-bold', 'left', 'top') end) local TexturesWithMemoryLeak = {} local TexturesWithoutMemoryLeak = {} -- with memory leak addCommandHandler('ctextures', function() local startTime = getTickCount() for i = 1, 1000 do local file = fileOpen('images/example.dds') local pixels = nil if file then pixels = fileRead(file, fileGetSize(file)) fileClose(file) end local Texture = dxCreateTexture(pixels) if isElement(Texture) then TexturesWithMemoryLeak[#TexturesWithMemoryLeak + 1] = Texture end -- local Texture = dxCreateTexture('images/example.dds', 'dxt1') -- if not fileExists('images/example_dds.rgba') then -- local file = fileCreate('images/example_dds.rgba') -- local pixels = dxGetTexturePixels(Texture, 'plain', 'dxt1') -- if file then -- fileWrite(file, pixels) -- fileClose(file) -- end -- end -- if isElement(Texture) then -- TexturesWithMemoryLeak[#TexturesWithMemoryLeak + 1] = Texture -- end end local endTime = getTickCount() local timeTaken = endTime - startTime outputChatBox('Textures Created: ' .. #TexturesWithMemoryLeak) outputChatBox('Time Taken: ' .. timeTaken .. 'ms') end) addCommandHandler('dtextures', function() local TexturesDestroyed = 0 local startTime = getTickCount() for i, v in pairs(TexturesWithMemoryLeak) do if destroyElement(v) then -- remove texture TexturesDestroyed = TexturesDestroyed + 1 TexturesWithMemoryLeak[i] = nil end end local endTime = getTickCount() local timeTaken = endTime - startTime outputChatBox('Textures Destroyed: ' .. TexturesDestroyed) outputChatBox('Time Taken: ' .. timeTaken .. 'ms') end) -- without memory leak addCommandHandler('ctextures2', function() local Width, Height = 512, 512 local startTime = getTickCount() for i = 1, 1000 do local Texture = dxCreateTexture(Width, Height) if isElement(Texture) then local _File = fileOpen('images/example.rgba') if _File then local pixels = fileRead(_File, fileGetSize(_File)) fileClose(_File) if dxSetTexturePixels(Texture, pixels) then TexturesWithoutMemoryLeak[#TexturesWithoutMemoryLeak + 1] = Texture else destroyElement(Texture) end end end end -- attempt to create 1000 textures local endTime = getTickCount() local timeTaken = endTime - startTime outputChatBox('Textures Created: ' .. #TexturesWithoutMemoryLeak) outputChatBox('Time Taken: ' .. timeTaken .. 'ms') end) addCommandHandler('dtextures2', function() local TexturesDestroyed = 0 local startTime = getTickCount() for i, v in pairs(TexturesWithoutMemoryLeak) do if destroyElement(v) then -- remove texture TexturesDestroyed = TexturesDestroyed + 1 TexturesWithoutMemoryLeak[i] = nil end end local endTime = getTickCount() local timeTaken = endTime - startTime outputChatBox('Textures Destroyed: ' .. TexturesDestroyed) outputChatBox('Time Taken: ' .. timeTaken .. 'ms') end) -- addEventHandler('onClientResourceStart', resourceRoot, function() -- local Clothes = exports['nc_clothes']:getClothe() -- for i, v in pairs(Clothes) do -- if v.Texture and v.Texture ~= 'TXD' then -- dxCreateTexture(':nc_clothes/' .. v.Texture) -- -- local Path = ':nc_clothes/' .. v.Texture -- -- if fileExists(Path) then -- -- local _Path = sha256(Path) .. '.rgba' -- -- if fileExists(_Path) then -- -- local File = fileOpen(_Path) -- -- local pixels = fileRead(File, fileGetSize(File)) -- -- fileClose(File) -- -- local Texture = dxCreateTexture(pixels, 'dxt1') -- -- end -- -- dxCreateTexture(Path) -- -- setTimer(function() -- -- local Texture = dxCreateTexture(Path) -- -- local pixels = dxGetTexturePixels(Texture, 'plain', 'dxt1') -- -- if not fileExists(sha256(Path) .. '.rgba') then -- -- local file = fileCreate(sha256(Path) .. '.rgba') -- -- if file then -- -- fileWrite(file, pixels) -- -- fileClose(file) -- -- end -- -- destroyElement(Texture) -- -- end -- -- outputChatBox('Texture saved: ' .. sha256(Path) .. '.rgba') -- -- end, 2, 1) -- -- end -- end -- end -- end)