code: def test_preloaded_checkpoint_lifecycle(tmpdir):
      """Tests that the preloaded checkpoint contents gets cleared from memory when it is not required anymore."""
      model = BoringModel()
      trainer = Trainer(default_root_dir=tmpdir, max_steps=1)
      trainer.fit(model)
  
      connector = trainer._checkpoint_connector
  
      assert not connector._ckpt_path
      assert not connector._loaded_checkpoint
  
      connector.resume_start()
      assert not connector._ckpt_path
      assert not connector._loaded_checkpoint
      connector.resume_end()
      assert not connector._ckpt_path
      assert not connector._loaded_checkpoint
  
      ckpt_path = trainer.checkpoint_callback.best_model_path
      trainer = Trainer(default_root_dir=tmpdir, max_steps=2)
      connector = trainer._checkpoint_connector
      connector.resume_start(ckpt_path)
      assert connector._ckpt_path == ckpt_path
      assert connector._loaded_checkpoint
      assert isinstance(connector._loaded_checkpoint, dict)
      trainer.state.fn = TrainerFn.FITTING
      connector.resume_end()
      # not cleared until next restoration, as the user might access it through `trainer.ckpt_path`
      assert connector._ckpt_path == ckpt_path
      assert not connector._loaded_checkpoint
  
file_path: pytorch-lightning/tests/tests_pytorch/trainer/connectors/test_checkpoint_connector.py
imports: import os
  from unittest import mock
  from unittest.mock import Mock
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.callbacks import ModelCheckpoint
  from lightning.pytorch.demos.boring_classes import BoringModel
  from lightning.pytorch.trainer.states import TrainerFn
  from lightning.pytorch.utilities.migration.utils import _set_version
label_desc: Use image node_id 1 for calling a global function with example usage: test_preloaded_checkpoint_lifecycle(tmpdir) without return types