Hot Reload and Hot Restart


Hot Reload and Hot Restart Interview with follow-up questions

1. What is the difference between hot reload and hot restart in Flutter?

Both speed up development by avoiding a full rebuild, but they differ in what they preserve:

Hot reload injects updated Dart source into the running app on the Dart VM and rebuilds the widget tree, preserving the current app state. It's near-instant and ideal for tweaking UI and layout. Because it only re-runs build, it has limits: changes to global/static initializers, main(), initState, enums-to-classes, or app-level structure won't take effect, and it can't reload if the running state is incompatible with the new code.

Hot restart rebuilds the app from scratch — it discards all state and re-runs main(). It's slower than hot reload but still much faster than a full native rebuild, and you use it when a change isn't picked up by hot reload (initializers, app structure, native code excepted).

Two interview gotchas: (1) both rely on the Dart VM's JIT in debug mode, so neither exists in release/profile builds (those are AOT-compiled); and (2) full native code changes (platform channel/plugin code, pubspec dependency changes) require a complete flutter run rebuild, not just a hot restart.

↑ Back to top

Follow-up 1

Can you explain a scenario where you would use hot reload?

Hot reload is particularly useful during the development process when you are making frequent changes to your code. It allows you to see the effects of your changes immediately without having to manually navigate to the specific screen or state in the application. For example, if you are working on a UI component and want to see how it looks with different styles or layouts, you can make the changes in your code and use hot reload to instantly see the updated UI without losing the current state of the application.

Follow-up 2

In what situation would you prefer hot restart over hot reload?

Hot restart is preferred over hot reload in situations where you have made changes to the application's configuration or when you want to reset the application's state. For example, if you have added or removed a dependency in your code, you would need to perform a hot restart to apply the changes. Similarly, if you want to start the application from a clean state, you can use hot restart to discard the current state and start fresh.

Follow-up 3

What are the advantages of hot reload?

Hot reload offers several advantages for Flutter developers:

  1. Faster development: Hot reload allows developers to see the effects of their code changes immediately, reducing the time spent on manually navigating to specific screens or states in the application.

  2. Preserves state: Hot reload preserves the current state of the application, allowing developers to continue their work without losing any data or progress.

  3. Iterative development: Hot reload enables developers to iterate quickly on their code, making small changes and seeing the results in real-time. This iterative development process can lead to faster bug fixing and feature implementation.

  4. Enhanced debugging: Hot reload makes it easier to debug code by allowing developers to quickly test and validate their changes without having to restart the entire application. This can help in identifying and fixing issues more efficiently.

Follow-up 4

What are the limitations of hot restart?

While hot restart is a useful feature, it also has some limitations:

  1. Slower than hot reload: Hot restart is slower than hot reload because it needs to rebuild the entire application from scratch. This can result in longer wait times when applying code changes.

  2. Resets state: Hot restart discards the current state of the application, which can be problematic if you are working on a specific screen or state and want to preserve the data or progress.

  3. Loss of unsaved data: If you have any unsaved data in the application, performing a hot restart will cause the data to be lost as the application starts fresh.

  4. Interrupts user experience: Hot restart interrupts the user experience as the application needs to be completely restarted. This can be disruptive if the user was in the middle of performing an action or interacting with the application.

2. How does hot reload enhance the development process in Flutter?

Stateful hot reload injects updated source into the running Dart VM and rebuilds the widget tree while preserving app state, so you see UI changes in well under a second without losing where you were (the screen you navigated to, form input, scroll position). That tight feedback loop lets you tweak layout, styling, and copy iteratively, fix bugs in place, and experiment with designs far faster than a rebuild-and-relaunch cycle. The follow-up to be ready for: it works only in debug builds (it relies on the JIT VM), and some changes — main(), initState, global initializers, or native code — still require a hot restart or full rebuild.

↑ Back to top

Follow-up 1

Can you explain the internal working of hot reload?

During hot reload, Flutter rebuilds the widget tree of the app, applying the changes made in the code. It does this by comparing the new code with the previous code and identifying the differences. It then updates the relevant parts of the widget tree, preserving the state of the app as much as possible. This allows developers to see the changes instantly without losing the current state of the app.

Follow-up 2

How does hot reload handle the state of the application?

Hot reload in Flutter is designed to preserve the state of the application as much as possible. When a hot reload is triggered, Flutter rebuilds the widget tree and applies the changes made in the code, but it tries to keep the existing state intact. This means that if there are any changes to the state variables or the UI hierarchy, Flutter will update them accordingly without resetting the entire state of the app.

Follow-up 3

What happens to the widget tree during a hot reload?

During a hot reload, Flutter rebuilds the widget tree of the app. It compares the new code with the previous code and identifies the differences. It then updates the relevant parts of the widget tree, preserving the state of the app as much as possible. This means that any changes made to the UI hierarchy, such as adding, removing, or modifying widgets, will be reflected in the updated widget tree without losing the current state of the app.

3. What is the impact of hot restart on the state of the application?

A hot restart rebuilds the app from scratch — it re-runs main() and resets all in-memory state, so anything held in State objects, providers, or other runtime variables is lost and the app returns to its initial route. This is the deliberate difference from hot reload (which preserves state): you use hot restart precisely when you want a clean slate or when a change (e.g. in initState, global initializers, or app structure) isn't picked up by hot reload. Note it still only resets Dart state — it doesn't restart the underlying native process, and it's a debug-mode feature.

↑ Back to top

Follow-up 1

How does hot restart differ from a full app restart?

A hot restart and a full app restart both restart the application, but there is a key difference. During a hot restart, the application is restarted without rebuilding the entire app from scratch. This allows for faster restart times compared to a full app restart.

Follow-up 2

What happens to the widget tree during a hot restart?

During a hot restart, the widget tree is rebuilt. This means that any changes made to the widget tree before the hot restart will be lost. However, the hot restart process tries to preserve the current state of the widgets as much as possible.

Follow-up 3

Can you explain a scenario where hot restart can be more beneficial than hot reload?

Hot restart can be more beneficial than hot reload in scenarios where the changes made to the code require modifications to the app's state or the widget tree. Hot reload only updates the code changes, while hot restart restarts the entire application, allowing for a clean state and widget tree. This can be useful when testing changes that affect the overall behavior of the app.

4. Can you explain the role of Dart's 'Isolate' in the process of hot reload and hot restart?

Quick correction to the premise: hot reload does not replace or spawn a new isolate — it reuses the same isolate. An isolate in Dart is an independent unit of execution with its own memory heap and event loop (isolates don't share memory; they communicate by message passing). Your Flutter app's UI runs on a single main (root) isolate.

Here's how each operation relates to it:

  • Hot reload: the running main isolate's Dart VM accepts the updated source and re-runs the widget tree's build methods. The isolate keeps living, which is exactly why state is preserved — the heap isn't discarded.
  • Hot restart: the main isolate's state is torn down and main() re-runs from scratch, so all in-memory state is lost, but it's still a Dart-level reset, not a new OS process.

Both depend on the JIT-mode Dart VM available only in debug builds. The broader point interviewers may chase: heavy work shouldn't block the UI isolate — offload it with Isolate.run (or compute) so the UI stays at 60/120fps. So isolates are central to concurrency, but they aren't swapped during hot reload.

↑ Back to top

Follow-up 1

How does 'Isolate' contribute to maintaining the state of the application?

The 'Isolate' in Dart is responsible for maintaining the state of the application. When a hot reload or hot restart occurs, the existing 'Isolate' is replaced with a new one, but the state of the application is preserved. This is achieved by isolating the stateful parts of the application from the code that is being replaced. The state is then passed to the new 'Isolate' so that it can continue from where the previous 'Isolate' left off. This allows developers to make changes to the code without losing the current state of the application.

Follow-up 2

What is the role of 'Isolate' in the execution of Dart code?

In Dart, 'Isolate' is responsible for executing Dart code concurrently. Each 'Isolate' runs in its own memory space and has its own event loop. This allows for true parallelism in Dart programs, as multiple 'Isolates' can execute code simultaneously. 'Isolates' communicate with each other through message passing, allowing for inter-isolate communication. The 'Isolate' API in Dart provides methods to create and manage 'Isolates', making it easy to leverage the power of concurrent execution in Dart applications.

5. How does Flutter's hot reload and hot restart enhance developer productivity?

Hot reload and hot restart shorten the edit-see-result loop from the tens-of-seconds a native rebuild takes down to roughly a second or less. Hot reload injects updated code into the running Dart VM and rebuilds the widget tree while preserving app state, so you can adjust layout, styling, and logic and immediately see the result on the exact screen you were on — no re-navigating, no re-entering data. Hot restart gives a fast clean-slate reset (re-runs main(), drops state) for changes hot reload can't apply. Together they make UI iteration and bug-fixing far tighter, which is one of Flutter's biggest day-to-day productivity wins. The caveat to mention: both are debug-only (they rely on the JIT VM), and native or dependency changes still need a full rebuild.

↑ Back to top

Follow-up 1

Can you share any personal experience where hot reload or hot restart significantly improved your development process?

Yes, I can share a personal experience where hot reload significantly improved my development process. In one of my Flutter projects, I was working on implementing a complex UI design. With hot reload, I was able to make changes to the code and instantly see the effects in the running application. This allowed me to quickly iterate and fine-tune the UI elements until they matched the design specifications. Without hot reload, I would have had to rebuild and restart the application after each code change, which would have been time-consuming and hindered my productivity.

Follow-up 2

How does hot reload contribute to faster UI development?

Hot reload contributes to faster UI development by providing a near-instant feedback loop for developers. With hot reload, developers can make changes to the UI code and immediately see the results in the running application. This eliminates the need to manually rebuild and restart the application after each change, saving valuable development time. Hot reload also allows developers to experiment with different UI designs and layouts more easily, as they can quickly iterate and see the effects of their changes in real-time. Overall, hot reload speeds up the UI development process and enables developers to be more productive.

Live mock interview

Mock interview: Hot Reload and Hot Restart

Intermediate ~5 min Your own free AI key

Your voice and your AI key never touch our servers; the key stays in this browser and is sent only to Google. Only your round scores are saved to track progress.

Next lesson Debug vs Release Mode →