You might be looking for Into the Wild with Emile Hirsch.
Into the Wild is a 2007 American biographical drama survival film written and directed by Sean Penn. It is an adaptation of the 1996 non-fiction book of the same name by Jon Krakauer based on the travels of Christopher McCandless across North America and his life spent in the Alaskan wilderness in the early 1990s. The film stars Emile Hirsch as McCandless with Marcia Gay Harden and William Hurt as his parents and also features Catherine Keener, Vince Vaughn, Kristen Stewart, and Hal Holbrook.
The finale of the plot summary reads:
Four months later at the abandoned bus, life for McCandless becomes harder and he becomes less discerning. As his supplies begin to run out, he realizes that nature is also harsh and uncaring. In the pain of realization, McCandless concludes that true happiness can only be found when shared with others and seeks to return from the wild to his friends and family. However, he finds that the stream he had crossed during the winter has become wide, deep, and violent due to the thaw, and he is unable to cross. Saddened, he returns to the bus, now as a prisoner who is no longer in control of his fate and can only hope for help from the outside. In a desperate act, McCandless is forced to gather and eat roots and plants, but he confuses similar plants and eats a poisonous one, thus as a result falls sick. Slowly dying, he continues to document his process of self-realization and accepts his fate, as he imagines his family for one last time. He writes a farewell to the world and crawls into his sleeping bag to die. Two weeks later, his body is found by moose hunters. Shortly afterwards, Carine returns her brother's ashes by airplane from Alaska to Virginia in her backpack.