  Relativistic heavy-ion collisions give rise to the formation of both
deconfined QCD matter and a strong magnetic field. The spin of heavy quarks is
influenced by interactions with the external magnetic field as well as by
random scatterings with thermal light partons. The presence of QCD matter
comprising charged quarks can extend the lifetime and strength of the magnetic
field, thereby enhancing the degree of heavy quark polarization. However, the
random scatterings with QCD matter tend to diminish heavy quark polarization.
In this study, we utilize the Landau-Lifshitz-Gilbert (LLG) equation to
investigate both these contributions. Taking into account the realistic
evolutions of medium temperatures and the in-medium magnetic fields at the
Relativistic Heavy-Ion Collider (RHIC) and the Large Hadron Collider (LHC), we
observe that heavy quark polarization is limited by the short lifetime of the
magnetic field and the high temperatures of the medium. Furthermore, we explore
the mass dependence of quark polarization, revealing that the polarization
degree of strange quarks is much larger than that of charm quarks.
