How Fragment re-creation works?

I’m not sure if my question is correct. But I’m confused if Fragments stays on the memory. I found out fragment’s onDestroy() and onDetach() are getting called during configuration change, just like Activity. But if I use Log.d() inside onCreate() of MainActivity to check fragment’s ID:

val currentFragment = supportFragmentManager.findFragmentById(
Log.d(TAG, "current fragment is ${currentFragment?.getId()}")

I found out it’s logging the same fragment ID on every screen rotation (configuration change). So I’m not sure if the fragment is really getting destroyed/detached.