Need Assistance?

support@tutorialshub.in

Pointers, Defer, Panic & Recover

The defer Statement (LIFO Cleanup)

ADVERTISEMENT
Go (Golang) Free Lesson
5 min read
ADVERTISEMENT

defer schedules a function call (like file.Close() or mu.Unlock()) to run right before the surrounding function returns—even if an error occurs! Multiple defers run in LIFO (Last-In, First-Out) order.

ADVERTISEMENT
Hi, I'm Tuby! Here to help you