Irish Blues said:
If Team A waives a player, he no longer counts for the team once he clears waivers or is claimed by another team. If the player's team then uses him in a game (and here's where things are completely unclear) I would believe that he begins to count from the day he once again plays for his team.
In the case of Mogilny, once New Jersey waived him another team could have picked him (and his contract) up and New Jersey would have incurred no cap hit. But once New Jersey sent Mogilny to the AHL, he would have had to clear recall waivers and that's where the "New Jersey takes half the cap hit if someone claims him" talk starts up. Technically, Malakhov was waived and never designated for assignment so he quit counting once he cleared waivers - so hopefully that answers all of your questions.
This leaves the whole "player is claimed on recall waivers and later ends up to another team, what happens to the team that lost him on recall waivers" question still unanswered - but with Rico Fata going to Washington, we may get an answer on that shortly.
Actually, once Team B claims a player on waivers (or Team A does not remove him from their roster or later reinstates him), he immediately will count against Team B's (or A's) cap - a player claimed has to be added to the active roster - even if he hasn't played a game yet. NHL salaries are paid per day, not per game. If he is on an active NHL roster and is getting paid by a team, he counts against that teams cap.
One other caveat.
Normally a player who clears waivers and is removed from the active roster no longer counts against the cap, however there is an exception for a player 35 yo or older who signs a multi year deal - even if he is waived (or retires) he still counts against the teams cap during the second and later years of the contract (unless he is claimed or traded to another team).
This clause was put in to prevent a team from signing an aging vet to a long term deal that neither expected the player to finish as a way to circumvent the cap.
This clause affected Mogilney, Malakhov, and Andrechuk this year - actually it will begin to affect them next year.
Mogilny no longer counts against the Devil's cap this year (since he was waived and removed from the roster and sent down), however, he will count against the Devil's cap next year.