Gollum is both greedy for the ring and eager to get rid of the torment of the ring. In hundreds of years, Gollum was transformed from a friendly and self-sufficient hobbit into an alien in a humid cave. Even Gollum himself will see his ugly reflection and his distorted dark temperament when drinking water by the river, which is undoubtedly a great torture for him. The occasional soberness will make him extremely eager to be free from the great bondage of the ring.
At the doomsday volcano, Gollum's two wishes came true at the same time. He regained the ring that he dreamed of and longed to have again. He was also freed from the ring and died with the ring. In a sense, if you regain the ring forever, you don't have to worry about losing the ring. If you lose the human form, you will lose the human mind and won't be affected and tortured by the ring. It can be regarded as an individual redemption of coincidence in this work.
Source: @maxpaulart