I have heard an argument that "when Jesus died, all of your sins were still in the future, but they were already forgiven through His sacrifice." It's entirely spurious. Sins are not forgiven by simply being ignored by either you or God. God's love is both unconditional and conditional at the same time; but forgiveness of sins is 100% conditional on: repentance, penance, and (upon being restored by the Holy Spirit) reformation.
Reformation signifies improvement which can be in any virtue or even art but which is generally ordered toward the growth of charity.
(All virtues are in the service of happiness, but charity is closest to it.)
Since man is mortal, improvement must stop at dying and at death. Improvement is possible only here and no longer in the hereafter. Therefore, if a man dies with a sin upon his soul for which he has not repented, reformation cannot be a condition of having this sin forgiven.
I also cannot insist that any penance will be demanded from this man when facing God and judgment (or "life review" which, however, may in itself be purgatory).
Therefore, if one dies with his grace stained by a sin, he will need only to repent, which should be possible in or before entering heaven, and all will then be well.
As a result, one should not worry that he should "die in the state of grace" but rather that he should live in the state of grace and demonstrate continuous progress throughout his life if at all possible.