Any healing prior to picking up Candy Heart will not provide stat boosts.
The stat bonuses are "stored" on the Candy Heart. Dropping or losing it in any way won't immediately revert the bonuses gained, only when Isaac's stats are updated again. The respective stat changed is the one that loses the Candy Heart bonuses.
The bonus stats will be lost if Isaac's stats are updated by dropping out of the game or if the game crashes.
The stat bonuses are seeded, meaning the same stat ups will apply in the same order in the same seed.
Glowing Hour Glass: Stat boosts acquired by red hearts will not be lost after Glowing Hour Glass is used, allowing the same hearts to be picked up multiple times. The bonuses are added to the same stats, in the same order as before using the Glowing Hour Glass.