Memory consumption becomes too large to create thumnails

Summary

When I upload image files, platform requires too large amount of memory about 1GB.
If my EC2 instance is t2.micro which has 1GB of memory. I have to add swap or migrate to
larger instance to keep it working. Otherwise, It must killed by OOM-Killer.

Therefore, I have a work around, however, is it strange behavior?

Steps to reproduce

I found this issue after upgrading 4.7.x. Also 4.8.0 still causes this issue.
Only upload any size of png or jpg image files cause this, I use only 170KB png and jpg.
Other formats like pdf and docx are okay.

Expected behavior

Keep ordinal small footprint of platform is like this.
$ ps aux |grep platform
root 5374 0.0 4.6 286556 46896 ? Ssl 13:28 0:00 bin/platform

Observed behavior

Mar 22 13:28:50 ip-172-xx-xx-xx kernel: [1718321.916115] Out of memory: Kill process 5020 (platform) score 820 or sacrifice child
Mar 22 13:28:50 ip-172-xx-xx-xx kernel: [1718321.919535] Killed process 5020 (platform) total-vm:2189672kB, anon-rss:858288kB, file-rss:0kB, shmem-rss:0kB

it’s too large.

Best regards

Another user reported a similar issue: https://github.com/mattermost/mattermost-server/issues/8450, and also enabled swap to resolve the issue. We have been unable to reproduce the crash thus far, but we’d love your help in adding context to the linked Github issue.

Note that (as I posted in the linked issue), we do generally suggest (or at least focus on) 2 vCPUs/cores, 4 GB RAM, and 45-90 GB storage aiming at 250-500 users, but nothing fundamentally ought to preclude running smaller teams on smaller boxes.