20 year rule (New Orleans would be largely underwater if it wasn't for its walls).
The Berlin wall is also fairly well known. Within cities there are the Belfast peace walls.
Assuming you are asking about purely military defence then mid to late 19th century depending on how you define your terms. The last walls defending Portsmouth were the Hilsea lines that were completed (mostly) in 1871 however they only defend Portsmouth on one side. The last walls what wrapped around the city were last worked on a decade earlier.
People stopped building them for a mix of reasons. They became less effective. Party because a properly equipped enemy could get through them but also because they didn't do much to stop the enemy bombarding the city with artillery. In modern terms it doesn't matter how many defensive structures south Korea puts along the DMZ to the north of Seoul (probably the closest analogue to a modern city wall) North Korea can level Seoul with artillery in fairly short order.
Cities got bigger. Modern Southampton is about 73 square kilometres in size. The walled area was around a quarter of square kilometre. This means that walls have to be longer which costs more and requires more manpower to be useful. So less effective walls are becoming more expensive.
At the same time other options appear. Rather than continuous walls isolated forts become an option. Place then a cannon's shot apart an anyone trying to move between them gets hit from both flanks.
As to what happened to them. Well some are still there. You can walk the walls of York or Conway/Conwy. A fair bit of Canterbury's walls are still there. A lot were robbed of stone over the centuries to the point where they ceased to exist. Others (Portsmouth, Hull ) were deliberately removed to free up land for other purposes. Since walls were tied to civic pride they were sometimes removed as a punishment (Northampton).
There are as many answers to this question as their are walls - and there are a fuckton of walls, to use the academic term.
If I can tweak the question, I'll provide an answer to when (vaguely) cities in Europe (sorry not-Europe, but hope somebody can help me out here) began to shed walls so tightly encircling an urban center - that is to say, walls which demarcated and often starkly an urban form from a rural, suburban form. "Suburban" in the old sense; i.e. in between farm and city center.
/u/nothingtoseehere____ makes a good point: "walls" did not disappear so much as technological improvements of artillery during the early industrial-era required many cities to develop a different model of "walls", perhaps more precisely "fortification". Each city will have a different experience, influenced by the form of the government, whether or not the city was surrounded by hostile territories, at one point the host political entity encouraged industrial development, and what the dominant city-planning (or what would become "city-planning") notions were at the time. Let's just use "Model City" as a basic generalization.
The old masonry, ramparted, and earthen battered walls typical of the early modern period were effective deterrents to siege artillery whose range and trajectory were limited by smoothbore barrels. Improvements in both accuracy and range through the wide adoption of rifled siege artillery resulted in a situation in which a well-drilled artillery force (Prussia in particularly, was notorious for the wall-destroyed capabilities) could lob shells over the older-model city walls. "Model City" would likely have had at this point a substantial perimeter wall and a "demarcation line" stretching a considerable distance (kilometers, usually) around the fringe of the wall with intermittent dikes, moats, or water barriers; the purpose of such a systems was to present an open line of fire from the fortifications of an attacking forces that had to traverse both open land and artificial chokepoints all whilst under punishing artillery and small arms fire. Anyone that built a structure in Model City's demarcation line was liable to have it destroyed by the military upon a whim or surely obliterated during (usually prior to) hostile periods.
However, if a force can simply lob shells over such a wall at distance outside the range of defensive artillery, then a demarcation isn't much good. So in the early to mid 1800s, cities in Europe start to develop various forms of outer defensive rings - often utilizing the star fort as important elements as it's easier to secure from artillery and, when well-placed, can prevent an opposing army from assuming a threatening position. Many cities also sought to improve the interior defenses as well.
But artillery wasn't the only countervailing pressure against walls. So was industry, liberalization, and internal migration. Most absolutists states in Europe enforced rigid monopolies on regional trade, prevented the establishment of commercial centers in proximity to the traditional seat of power, and often prevented "citizens" from moving from rural land to these cities. With gradual liberalization, industrialization, and loosening restrictions on the rural population (who could now "sell their labor") resulted in a major rural-to-urban migration in the mid-1800s. Model City would still have been constrained by it's walls and demarcation line at this point, so the urban industrial migrants would've piled into an already and increasingly cramped, deteriorating situation within the city's walls. The stark dichotomy with a cleared, open expanse just beyond the walls would've been moving to many city leaders.
It's those conditions: industrialization, technological improvement in artillery, and internal migration that ultimately did in the confining city walls. What happened after is actually quite interesting. In Model City's case (as with many other European cities), the military would abandon the interior demarcation line for a outer ring of defenses, opening up that land for real estate speculation. Speculators would build up tenements quickly as the old, confined city's population burst into the formerly empty (or mostly empty) land just outside the city walls. The walls themselves would persist in Model City for a few years, but increasing population and commerce outside the city walls would generate traffic that could only pass through specific, narrow gates that quickly became too congested to function. The practice of closing the gates at dusk would also annoy the increasingly substantial city with the ultimate solution of abolishing the walls entirely. The alignment of the walls would be a different story, in Model City's case, the land would be reutilized as a boulevard encircling the medieval town. The two, new railways stations lying just beyond the former city walls at opposing ends (easiest way to find the edge of a medieval district in Europe is to find the main station, it's usually on the fringe) would be connected by either a trench, open rail bed through the former demarcation line, or, in the early 20th century, a tunnel.
So to a certain extant, the geographies of many European cities are still determined by walls: the position of the main railway stations and their connections, the 19th century developed areas (which are often larger in scale than the older areas), the major arteries entering the city were largely borrowed from the former approaches to the city gates, the inner-ring circumferential boulevard along the old alignment of the walls, and the now-landscaped ramparts and water defense that have become city parks are all contemporary and relevant left-overs.
Vienna turned its walls into a boulevard (the Ringstrasse) during the mid-19th century. The Ringstrasse became sort of a showcase of Austrian power and culture -- the parliament, the town hall, a number of theaters and art museums and so forth were built there, which is handy for modern tourists. Something similar happened in a number of other Austrian cities. Brno in the Czech Republic is another example, although since its geography is a little different (it's hillier than Vienna) it's kind of a series of connected boulevards, not a ring.
The Seoul City wall was built in 1394, two years after the Joseon Dynasty was founded. It was a stone/brick/earthen structure and it had the earthen sections replaced in 1422 and it underwent a major restoration in 1704.
By the 20th century, Seoul had grown so much that, in 1907, sections of the wall near Namdaemun (Great South Gate) were demolished to expand the road network. When the Japanese took over Korea, they demolished sections of the city wall, and they allowed other portions to be neglected and fall apart.
However, in 1968, North Korean agents infiltrated Seoul in an attempt to assassinate Park Chung-hee. Shortly thereafter, the South Korean government rebuilt sections of the Seoul city wall behind Chungwadae (the Blue House, the executive mansion) for security purposes. A few years ago, they finally opened the wall up to visitors to hike along.
Also in Korea, the city of Suwon has a complete fortress that is complete, Hwaseong Fortress. It was built between 1794-1796 in an attempt to move the capital out of Seoul. Pyongyang North Korea also has/had a city wall but I can't find much information on it. Most of Pyongyang was destroyed during the Korean War, but they still have the main gate, Taedongmun, sitting on the bank of the Taedong River.
So, in Korea, the last walled city that was built was Suwon/Hwaseong Fortress just at the end of the 18th century. It's important to note that while Korea has palaces, they are NOT castles/keeps like European castles. While Hwaseong was a walled city and it had a walled palace inside of it, people would have still lived outside of the walls as well. Beyond the walled cities, there are also fortresses around Korea known as san-seong. These are very similar to walled cities. Namhansanseong takes up considerable space and was built with fortifications on mountain ridges with place to live in the valley. In terms of size, it is a bit LARGER than the walled portion of Seoul.
In South Korea, the Seoul wall and Hwaseong are both still standing and are major tourist attractions. The Seoul wall is still standing through the mountains, but in the city area, most of the walls has been torn down. There are a few places within the urban area where you can see the wall, and the city has been painting or laying bricks down on the ground to trace the area where the wall used to be. Hwaseong is complete and the city of Suwon has grown around it. A few sections of the wall have been cut/enlarged to allow vehicles through and around Paldalmun, the wall has been removed, but the path is still clear.
Here's a kind of followup question, but when did sieges become less popular, and why? Was it perhaps that sieges became more effective? Where attacking troops would just starve people by surrounding their cities and building other fortifications arround them?
It seems to me, with more modern examples, like old fort henry, that there was a shift between fortifying cities and fortifying key military positions where forts would be walled, but cities would be basically left defenseless. More of a military campaign to defend larger expanses of territory, within which cities would be found.
Whereas it seems to me that prior to then, the castke would be built on strategic areas, and the people would live within them.
Im also wondering whether industrialization may have add an impact, since mills and stuff like that would have required more space and access to a flowing river.