{"action":"opened","issue":{"url":"https://api.github.com/repos/thegrb93/StarfallEx/issues/39","repository_url":"https://api.github.com/repos/thegrb93/StarfallEx","labels_url":"https://api.github.com/repos/thegrb93/StarfallEx/issues/39/labels{/name}","comments_url":"https://api.github.com/repos/thegrb93/StarfallEx/issues/39/comments","events_url":"https://api.github.com/repos/thegrb93/StarfallEx/issues/39/events","html_url":"https://github.com/thegrb93/StarfallEx/issues/39","id":152760371,"number":39,"title":"Memory leak using bass.loadFile","user":{"login":"ThatOneCheetah","id":9394711,"avatar_url":"https://avatars.githubusercontent.com/u/9394711?v=3","gravatar_id":"","url":"https://api.github.com/users/ThatOneCheetah","html_url":"https://github.com/ThatOneCheetah","followers_url":"https://api.github.com/users/ThatOneCheetah/followers","following_url":"https://api.github.com/users/ThatOneCheetah/following{/other_user}","gists_url":"https://api.github.com/users/ThatOneCheetah/gists{/gist_id}","starred_url":"https://api.github.com/users/ThatOneCheetah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ThatOneCheetah/subscriptions","organizations_url":"https://api.github.com/users/ThatOneCheetah/orgs","repos_url":"https://api.github.com/users/ThatOneCheetah/repos","events_url":"https://api.github.com/users/ThatOneCheetah/events{/privacy}","received_events_url":"https://api.github.com/users/ThatOneCheetah/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-05-03T12:21:11Z","updated_at":"2016-05-03T12:21:11Z","closed_at":null,"body":"I have discovered that loading many streams using `bass.loadFile` and then deleting/refreshing the chip doesn't always call the `stop` method on the bass classes and dispose of them properly.  \r\n  \r\nI don't have the exact code to replicate such thing but  \r\n```\r\nlocal sounds = {}\r\nfor i=1,256 do\r\n    bass.loadFile( \"sounds/synth/sine_440.wav\", \"3d noblock noplay\", function( chan )\r\n        chan:play()\r\n        chan:setVolume( 0 )\r\n        sounds[i] = chan\r\n    end\r\nend\r\n```\r\nshould suffice to recreate the issue.  \r\n  \r\nThe current dirty-fix you can implement is:  \r\n```\r\nif not globaltables.global.dispose_bass then globaltables.global.dispose_bass = {} end\r\nif not globaltables.global.dispose_bass[chip()] then globaltables.global.dispose_bass[chip()] = {} end\r\n\r\nlocal function dispose_bass()\r\n    if globaltables.global.dispose_bass then\r\n        for e, t in pairs( globaltables.global.dispose_bass ) do\r\n            if not isValid(e) or e==chip() then\r\n                for _, b in pairs( t ) do if b.stop then b:stop() end b = nil end\r\n                t = nil\r\n            end\r\n        end\r\n    end\r\nend\r\n\r\ndispose_bass()\r\nhook.add( \"Remove\", \"dispose-self\", dispose_bass )\r\n\r\nfor i=1,256 do\r\n    bass.loadFile( \"sounds/synth/sine_440.wav\", \"3d noblock noplay\", function( chan )\r\n        chan:play()\r\n        chan:setVolume( 0 )\r\n        sounds[i] = chan\r\n        globaltables.global.dispose_bass[chip()][#globaltables.global.dispose_bass[chip()]+1] = chan\r\n    end\r\nend\r\n```\r\n  \r\nI'm not sure whether this is also the case with `bass.loadURL`, however, I do presume so.\r\n\r\n"}}