Giving from one's wealth with a sincere heart in order to earn the good pleasure of Allah is a mark of faith. Believers who spend generously are praised and given good tidings in many verses. Allah mentions a subtle aspect of spending—that by the giving away of what one loves, he will attain righteousness:
You will not attain true goodness until you give of what you love. Whatever you give away, Allah knows it. (Surah Al ‘Imran; 92)
The importance attached to something is linked to how much one sacrifices in order to attain it. Reluctance to give up particular things means that those things are thought to be dearer. Since nothing is more precious than the approval and mercy of Allah, a true believer can give away anything he owns in an instant. A contrary attitude would mean that worldly things are dearer than the good pleasure of Allah, so he would not attain the state of righteousness mentioned in the Qur'an.
It may be that a person donates much, renders important services for the cause of religion, and performs his acts of worship regularly. He may also have religious knowledge. Yet, his failure to let go of something he loves and contribute it for the cause of Allah when necessary shows weakness of faith and failure to grasp the essence of religion. Because this would mean that he prefers that thing to the good pleasure of Allah. In this sense this would put all his good deeds at risk, even if he thinks what he had done is good.
A Muslim should love Allah above all else and love created things only because they are manifestations of Allah's creative artistry or because Allah loves them too. In Allah's sight, this is the only legitimate way of love. This perception will allow a person to part with anything he loves at any time. Because his love is primarily for Allah, he loses nothing. For Allah pervades and embraces everything. He is closer to him than his jugular vein. In fact, he attains greater love and blessing because he has acted in compliance with Allah's will. He does not regret what he gave; on the contrary, he feels pleased. This is the attitude of a true Muslim.
But if a person loves something or someone as autonomous and independent of Allah, he ascribes it as an associate to Allah (Allah is Surely Beyond That) and becomes an idolater. If he must possess something but, at the same time, does so in accordance with Allah's commands, Allah may will to purify him from the "association" he fell into through his ignorant desires. Finally he will attain goodness and enjoy Allah's mercy.