Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCD Memory Bloat Swift on Linux

I'm working on a Producer-consumer problem with an unbounded consumer. The producer can put as many tasks into the processing queue as it wants. When the queue is empty the consumer will block the thread.

while true {
    do {
        guard let job = try self.queue.dequeue() else { return }
        job.perform()

    } catch {
        print(error)
    }
}

Normally I would put everything in the loop in an autorelease pool, however, it's not available on Linux. It seems as though ARC is never releasing the objects in the loop. How should I go about controlling memory usage?

like image 873
twtr Avatar asked Aug 10 '17 21:08

twtr


1 Answers

I don't believe memory spikes due to autorelease pools should be a thing on Linux. It's possible that something else could be holding onto a reference to one of your objects, though. Try setting a breakpoint in the middle of the loop, then click on "Debug Memory Graph" in the debugger to see what objects have references to the objects that are piling up. This can help determine the cause of objects that stick around longer than they ought to.

like image 106
Charles Srstka Avatar answered Oct 20 '22 09:10

Charles Srstka