fill algorithm

Why does fill algorithm use so much memory ?
Are you referring to floodfill? Like what's used in MS Paint or Photoshop to fill in areas of a canvas with color?

A poorly-implemented fill algorithm can use tons of memory or stack overflow because it uses 4x recursive calls at each pixel. That makes the memory footprint 4x larger every iteration, which can eat up your memory.

So, you start at 1 pixel, and then the algorithm multiplies and tries to fill in the 4 neighboring pixels, and then those 4 pixels multiply into 16 pixels that call the function, etc. Of course, it isn't quite that bad, because you can stop the recursion early if you detect a pixel you can't fill, but it can still be resource-heavy if you're not careful.

https://en.wikipedia.org/wiki/Flood_fill
This article lists other methods that help to reduce the memory footprint.
Topic archived. No new replies allowed.