3 ms·
From my time at then-Facebook: ARC is a huge pain at scale (hundreds of developers contributing to the same codebase) because anyone anywhere can cause a retain
by School-Cotton 2y ago
From my time at then-Facebook: ARC is a huge pain at scale (hundreds of developers contributing to the same codebase) because anyone anywhere can cause a retain cycle.
E.g. imagine if you open some news feed story, then go back to news feed so the view controller you opened is lost, but the person who implemented that page was an android dev who recently switched to iOS and doesn’t know about weak pointers, and had something deep in the view hierarchy retaining a pointer to the root… now everything associated with that page is leaked, which can include megabytes of decoded images or worse, videos…
The issue was compounded by the fact that, at least at the time, their interview process primarily rewarded regurgitating memorized answers to leetcode problems as quickly as possible.
- refulgentis 2y agoRandom color commentary you might appreciate: I grew up on iOS for several years, then went to Google, and after a couple years migrated to working on Android's Springboard equivalent. One of the odder things to me about Android is this could happen too, with what felt like ~same rate as iOS. There wasn't nearly as good tooling as Instruments, instead it was ~always caught by testing but it was so much more work: testing was done on a batch of commits, so if there was a regression, there needed to be an additional layer of bisecting + test engineer in the loop to let you know it happened. If someone does Android regularly and sees this, I'm very curious what you use for detecting cycles: my iOS habit was to, every month or so, and with each release, sit down with this tool called "Instruments" that displayed live objects and run through the app, and see if there was any unexpected objects representing screens / core workflows piling up. I have a feeling this is totally possible on Android (maybe that Square leak canary library?), and it was more manually processed at Google because there was no way to enforce SWEs actually did it, and we couldn't(?)/didn't put the Square library in the OS.
- School-Cotton 2y agoDoesn't Android have a tracing garbage collector? How do retain cycles cause leaks?
- refulgentis 2y ago_Really_ handwaving here, tl;dr in a pure cycle scenario its resolved but it seemed it didn't help much compared to the number of footguns available. ex. felt like on iOS you'd cover 90% of cases by just "just do [weak self] in every dispatch_async" In Android you have to remember that, and there's this god-object called Context that you use to retrieve strings, images, and layouts (~XIBs). Each Activity (ViewController) has one and its incredibly easy to accidentally retain it, and thus the whole screen. The standard way of handling button presses / whatever IBActions are now also would cause it, and these heavily used things called BroadcastReceivers would usually be spun up when an Activity was started, and instantly form a cycle with the Activity that for some reason can't be noticed easily. Sorry for the handwaving, it's been very strange spending so much calendar time working on something I had to understand a lot less. (tl;dr: solo founder that shipped a point of sale system to 2,000 restaurants starting on iPad 1.0, had to get to 0 leaks all by myself. versus the warm safe blanket of bigco). This Medium article is an excellent overview I used to remind myself, though the AI art is incredibly shitty, enough to make me wonder if the article is plagirized. https://medium.com/@naeem0313/top-10-android-memory-leak-causes-and-how-to-avoid-them-b7ea67e716b6 https://medium.com/@naeem0313/top-10-android-memory-leak-cau...
- School-Cotton 2y agoMakes sense!