ID:2812636
 
Resolved
Some memory leaks were discovered with the handling of filters, especially in mutable appearances and animation.
BYOND Version:514
Operating System:Windows 10 Home
Web Browser:Chrome 104.0.0.0
Applies to:Dream Daemon
Status: Resolved (514.1586)

This issue has been resolved.
Descriptive Problem Summary:
Animating a filter creates new filter objects but doesn't properly cleanup the previous one, causing it to exist permanently and thus causing a memory leak.

Numbered Steps to Reproduce Problem:
1. Create and attach a filter to an atom
2. Animate that filter with its reference
3. The reference ID of the animated filter in the atom's filters list has changed, indicating a new object
4. Repeat the animation process a lot more times and track the memory usage reported in your OS - it keeps increasing as long as you create new animations

Code Snippet (if applicable) to Reproduce Problem:
atom
proc
OutputFilters()
var/output = "\["
for(var/filter in filters)
output += "[ref(filter)], "
output += "]"
world.log << output
mob
proc
AnimateFilter1()
if(!length(filters)) return
animate(filters[1], size = 5, time = 5)
OutputFilters()

AnimateFilter1Silent()
if(!length(filters)) return
animate(filters[1], size = 5, time = 5)

verb
AddFilter1()
filters += filter(type="blur", size=1)
OutputFilters()

AnimateFilter()
AnimateFilter1()

AnimateFilterN(n as num)
if(!length(filters)) AddFilter1()
for(var/i in 1 to n)
AnimateFilter1()
world.log << "Done"

AnimateFilterNSilent(n as num)
if(!length(filters)) AddFilter1()
for(var/i in 1 to n)
AnimateFilter1Silent()
world.log << "Done"

Calling AnimateFilterNSilent with a large number (like 1000000) will make dreamseeker/daemon rise to about 250 MB in size, and will keep rising as long as you repeat the calls. The reference IDs keep increasing in number, indicating that the previous IDs aren't released and available to be reused.

Expected Results:
Unused filters are properly garbage collected.

Actual Results:
Unused filters are staying alive with no actual reference pointing to them.

Does the problem occur:
Every time? Or how often? Every time
In other games? Yes
In other user accounts? Yes
On other computers? Yes

When does the problem NOT occur?
When you don't animate filters.

Did the problem NOT occur in any earlier versions? If so, what was the last version that worked? (Visit http://www.byond.com/download/build to download old versions for testing.)
The bug existed all the way back in 512.1454 and is still present in 514.1585

Workarounds:
None really, but it's not likely to cause immediate problems since it requires a very large number of animated filters to even notice.

Lummox JR resolved issue with message:
Some memory leaks were discovered with the handling of filters, especially in mutable appearances and animation.