Performancereact-nativeexpo-routermemory-managementperformanceandroiddebugging

The Navigation Bug That Ate 735 MB

12 min read
The CKE Kitchen Reports screen on a tablet, showing sales, average order, and refunds totals above a bar chart of sales per day, with the side rail of main screens on the left.

"It Feels Slow"

Casual Kitchen Express (CKE) is a food delivery platform I built as a portfolio concept: a customer app, a rider app, and a business app that runs a kitchen from a tablet. On 15 November 2026, a few days into the build, I was trying two new features in the business app, Practice orders and Reset. The app was sluggish. Taps took a beat too long. Screens dragged a little as they opened.

"It feels slow" is the most frustrating bug report there is, because it points at everything and nothing. It could be a slow network call, a heavy screen, a runaway timer, or the tablet itself. The test tablet is deliberately cheap: a Unisoc T310 processor with 4 GB of memory, running Android 12, about what a budget phone in Benin City would have. Cheap hardware was the point. If CKE ran well on that, it would run well on almost anything.

This post is how I tracked the slowness down, what was actually wrong, and how a one-line misunderstanding about a navigation function ended up in all three apps.

Measure Before You Guess

My first instinct was to start reading the code of the screens I'd just built. I didn't, because guessing at performance problems usually means fixing the wrong thing. Instead, I asked the tablet what was going on, over adb, Android's command-line bridge.

Two questions come first: is the processor busy, and is memory running out?

# How much memory one app is using (look for TOTAL PSS)
adb shell dumpsys meminfo com.armstrongaisosa.casualkitchenexpress.business

# How much memory the whole device has left
adb shell cat /proc/meminfo | grep MemAvailable

# What the processor is doing for one app
adb shell top -p <pid>

The answers were clear.

MeasurementResult
Free memory on the tabletAbout 80 MB of 3.9 GB
Swap in use1.1 GB
Business app735 MB
Customer app (also open)504 MB
ProcessorMostly idle

The idle processor ruled out a whole family of causes. Nothing was stuck in a loop, recalculating, or polling in the background. The tablet wasn't slow because it was working hard. It was slow because it had run out of memory, and Android was moving memory to and from swap to keep everything alive. Every tap waited on that shuffling.

One caveat matters here. These were development builds, which use far more memory than release builds, and the tablet was also running Gmail, YouTube, Chrome, and Google's own services. So 735 MB wasn't the number a real user would see. But a business app should never come close to that, debug build or not. Something was holding on to memory it didn't need.

A Leak, or Just Big?

A large number doesn't prove a leak. An app that loads a lot of photos and charts is going to use a lot of memory. The question is whether memory levels off or keeps climbing.

So I made a repeatable test. The business app has a guided tour for managers that opens all 14 of their main screens in turn, from the order board, walk-ins, and alerts through orders, riders, staff, the menu, rider pay, reports, and finance to settings and demo controls. I restarted the app fresh, noted its memory, ran the tour, and measured again. Then I ran it again.

StepMemory
Fresh start458 MB
After tour 1+98 MB
After tour 2+81 MB more

The first round of any test like this grows, because screens and photos load for the first time. The second round should be close to flat, because everything's already loaded. Instead, the second tour added nearly as much as the first. Memory that climbs by about the same amount every round is the signature of a leak.

Then came the clue that cracked it. After two tours, I pressed the tablet's back button, expecting to leave the app. Instead, it walked backwards through every screen I'd visited: Settings, then Finance, then Reports, then the menu, and on and on through both tours.

The back button was telling me the whole story. Every screen visited was still there, stacked one on top of another.

The Cause: navigate Doesn't Mean What I Thought

CKE's apps use Expo Router, which gives React Native apps file-based navigation. The business app has a side rail: a column of icons down the left edge of the tablet, one per main screen. Tapping an icon called this:

router.navigate(`/${screen}`);

I'd read navigate as "go to that screen": switch to it if it's already open, and open it if it isn't. That's how it used to work. But since Expo Router version 4, navigate behaves the same as push. It adds a new screen on top of the stack every time. The older "go back to it if it exists" behaviour moved to a separate function, dismissTo.

So every rail tap stacked a new screen. Stacked screens stay mounted. They keep their state, their images, and their charts in memory, ready for the user to press back to them. On a phone app where you go two or three screens deep and come back, that's what you want. On a tablet app where a kitchen manager hops between the board, orders, and reports all day, it meant the stack never stopped growing. A full shift of tapping around would eventually choke any device.

The bug wasn't in any one screen. Each screen was fine. The problem was how they were connected, which is why reading screen code first would have wasted my time.

The Fix: Main Screens Replace, Task Screens Push

The fix came down to separating two kinds of screen:

  • Main screens are the places you go: the rail items. Going to one should replace whatever is open, not pile on top of it.
  • Task screens are things you open from a list and come back from: a ticket, an order, a person, a menu item. Those should stack, so back returns you to the list.

A tiny helper handles the first kind:

import { router, type Href } from "expo-router";

/**
 * Opens a main screen (a side rail item) in place of whatever is open,
 * instead of stacking it on top. Task screens (a ticket, an order, a person)
 * still open on top of their list with router.push, so Back returns to the list.
 */
export function goTo(href: Href) {
  if (router.canDismiss()) router.dismissAll();
  router.replace(href);
}

dismissAll closes any task screens open on top, and replace swaps the current main screen for the new one. The stack never holds more than one main screen plus whatever task the user is in the middle of.

I swapped every rail tap, every tour step, and every "go to the board" style button over to goTo. Task screens kept router.push.

Fixing the stack changed one more behaviour that needed a decision. Before, pressing back on a main screen walked through history. Now there's no history to walk through. So pressing back on a main screen goes to the person's first screen, the order board for managers and kitchen staff, and pressing it there leaves the app, as Android users expect.

Proving the Fix

The same test, from a fresh start:

StepBefore the fixAfter the fix
Fresh start458 MB459 MB
Tour 1+98 MB+70 MB
Tour 2+81 MB+26 MB
Tour 3—+11 MB

That's the shape you want: a first round that loads things, then rounds that shrink towards nothing as memory levels off. My rough rule of thumb is under about 15 MB per round once warm. And the back button, the original clue, now behaved: back from Demo controls went to the board, and back from the board left the app.

Then I Checked the Other Two Apps

A bug caused by misunderstanding a function rarely lives in just one place. I'd written all three apps, so I'd misunderstood navigate in all three. I checked the customer and rider apps the same day.

Both use tabs along the bottom (Menu, Orders, Profile, and More for customers; Home, Queue, Earnings, and Me for riders), and tabs exist only once, so I expected them to be safe. They mostly were. But a few buttons that return to the tabs from a screen on top opened a whole new set of tabs each time.

In the customer app, Order tracking's "Back" and "Back to menu" buttons used router.replace with a tab route. Replacing the tracking screen with a tab route didn't return to the existing tabs. It created new ones on top. Six trips between Order tracking and Orders added 54 MB, and leaving the app afterwards took 14 presses of the back button: Orders, Menu, Orders, Menu, and so on.

In the rider app, "Back" from My deliveries used router.navigate("/(tabs)"), which, as I now knew, means push. Six trips between the Queue and My deliveries added 90 MB, and the back button cycled through Queue, Home, and My deliveries more than 16 times.

The fix was the same idea, shaped for tabs: close what's on top, then switch tab.

export function toTab(href: Href) {
  if (router.canDismiss()) router.dismissAll();
  router.navigate(href);
}

With nothing left on top, navigate just switches to the existing tab instead of stacking a new set.

AppSix trips, beforeSix trips, afterBack presses to leave, beforeAfter
Customer+54 MB+9 MB143
Rider+90 MB+23 MB16+3

Three back presses matches the screens actually open: tracking, Orders, Menu for the customer, and My deliveries, Queue, Home for the rider.

That gave me one rule for all three apps, which went into the project's design document: a button that returns to a main screen, whether a rail item or a tab, clears the screens on top first. Only task screens are pushed.

The Real Test: Release Builds

Development builds exaggerate memory use, so the final word had to come from release builds, the APKs people actually install. Before release 1.0.1, a script tapped through every screen of all three apps on the tablet for about 40 minutes in total, sampling memory and the processor as it went. Then it left each app idle for a minute, and in the background for another.

CheckResult
MemoryRises while browsing, then levels off: about 104 to 154 MB per app
LeaksNone
CrashesNone
Processor while in use7 to 14% of one core
Processor in the background0%
Screen drawing12 to 16 ms per frame once a screen is open

Before release 1.0.2, I ran the business app through every screen three times again. It started at 104 MB and then measured 149, 145, and 150 MB. That's flat, with no leak. For comparison, the debug build had been heading past 735 MB.

Turning a Bug Into a Habit

The fix took minutes. Finding it took longer, and I didn't want to find the next one by accident too. So the method became a written checklist, run on the tablet after any change that touches screens, lists, images, live data, timers, or navigation, and always on release builds:

  1. Start fresh and write down the numbers: the app's memory, and the device's free memory.
  2. Repeat the main flows several times: the tour, opening and closing orders, tracking and back.
  3. Measure after each round. The first may grow; later rounds should level off. Memory that climbs by the same amount every round is a leak.
  4. Count the back presses needed to leave. It should equal the screens actually open, not every screen ever visited.
  5. Check the processor at rest. An idle release build should sit near 0%. Anything working while nothing changes on screen, such as a timer, polling, or a looping animation, is a fault.
  6. Then read the code for the usual suspects: navigation that stacks main screens, timers and listeners without clean-up, long lists drawn in full, and full-size images in small places.

Step 6 is last on purpose. Reading code is where I wanted to start that evening, and it's the step least likely to find a problem like this one.

What I Took Away

"Slow" has a cause you can measure. One dumpsys and one look at the processor turned a vague feeling into a specific fact: out of memory, processor idle. That eliminated half the possible causes before I'd opened an editor.

The back button is a debugging tool. It shows you the navigation stack without any tooling at all. If it walks through screens you thought were closed, they aren't closed.

Read the docs for the version you're on. navigate changed meaning in a major version of Expo Router, and my mental model was from the old one. The code looked right and wasn't.

When you find a bug caused by a misunderstanding, search for the misunderstanding. The same wrong idea about navigate was in all three apps. Checking the other two the same day found two more versions of it before any user could.

Test on cheap hardware first. On a fast phone with plenty of memory, this bug would have stayed hidden for weeks, maybe until a kitchen manager's tablet ground to a halt mid-shift. The budget tablet found it on day five.

The full project, with screenshots of all three apps and their downloads, is on the Casual Kitchen Express case study.