I'm wondering primarily about barrel wear and how it would affect a given cannon's use, as well as how a gun was deemed no longer fit for military use and what happened to it after that.
The service life of cannon is a very complicated matter, and barrel life is just one part of it. A cannon can be decommissioned for any of a number of reasons that make it dangerous / ineffective to fire. It depends on a great number of factors, which I'll try to list below, non-exhaustively:
Cannon
Projectile
Service
So let's tackle these issues in order-ish.
Cannon
In the early days of artillery, cannon were cast in bronze. This made them extremely expensive, but bronze is a relatively good material. Compared to cast iron it is softer but far more ductile, resulting in a cannon that tends to tear instead of shatter when it malfunctions. And cannon do, and will, malfunction. Cast iron is much harder and cheaper, but also tends to fail by shattering, and a malfunctioning cast iron cannon instantly becomes a shrapnel bomb. Wrought iron is also a much softer material, but it wasn't castable, and had to be worked / forge-welded into cannon by wrapping reinforcing rings of iron around straight bars, which introduced a lot of inconsistencies in quality. It wouldn't be until 1855 with the Bessemer process that quality steel started to become a viable cannon material. And so the 1512 ship the Mary Rose carried a variety of bronze and iron cannon, and a mix of bronze and iron would continue to be used well into the 19th century.
Modern cannon are made of advanced steel alloys designed to stay rigid throughout their length even when hot from firing, plated with chrome to reduce barrel wear and corrosion, and stand up to a large number of high-power rounds being fired through them. It's much easier to put a definite service life to modern cannon, since the manufacturing process is much more standardized and consistent- for example the Rheinmetall 120mm L55 cannon is rated for 1500+ rounds at full charge, while the 16"/50 naval cannon had a barrel life of just 290 rounds when it first was fielded. This is distinct from the breech life, which is 4500 rounds for the Rheinmetall. I believe their lifespans are limited by internal barrel wear from the sheer pressures / temperatures they are exposed to, but do please correct me if I'm wrong.
An interesting article from the 1863 New York Times mentions discontent between wrought-iron metalworkers and the government, who put forth a requirement for a wrought-iron cannon with a service life of 1000 rounds, without "bursting or ... apprehensions of bursting". Nobody wanted to shoot a cannon they remotely thought might burst!
http://www.nytimes.com/1863/03/16/news/wrought-iron-cannon.html
Another possible advantage of bronze cannon is that the oxide of bronze is non-porous, meaning that bronze cannon don't rust destructively- a great advantage for seagoing cannon. Many bronze cannon, for example the Dardanelles gun, saw action decades (and in that case centuries) after they were first cast.
Until the development of consistent powder measurement and powder production, it would be impossible to predict exactly how much pressure a cannon would be subject to. In fact, it was impossible to predict how much pressure a cannon could withstand until you fired it. So every shot was a gamble! Even up until the American Civil War, guns were being chosen for their reliability- famously the 3-inch rifle in wrought iron, and the 12-pounder in bronze.
The shape of the cannon played a big role in determining how long it might last. When the powder charge goes off, the breech end (the end you point towards yourself) is subject to an immense amount of pressure. As people came to understand this, cannon started to be made with relatively bigger butts so they could withstand higher pressures, enabling faster projectiles and ultimately higher accuracy.
I say relatively, because cannon- due to the aforementioned worries- were usually over-engineered, so that any inconsistency in materials or manufacturing would be compensated for by the sheer mass of the gun. Modern cannon are tradeoffs between weight, toughness, and strength.
Early cannon were big, lumbering affairs, and burst with distressing frequency- famously Mons Meg, for example. By the 19th century, John Dahlgren had come up with a bulging design for cannon that put a lot more metal where the forces of firing were concentrated, which made for a much more reliable gun even though it was a cast-iron gun.
The Parrott rifle was built along the same ideas, with a large wrought-iron reinforcing band around a cast-iron barrel, but it was not quite as reliable as the Dahlgrens- it still burst with distressing frequency.
The metallurgy that goes into cannon-making is very, very interesting, though obsoleted with modern steelmaking. As mentioned, wrought-iron was not cast- it was worked. So wrought-iron cannon was made by welding together vertical metal bars and wrapping wrought-iron bands around them, eventually fusing them all into a cannon.
Cast iron cannon was made by, well, casting the iron in a mold. However, as the iron cooled, it shrank. Cooling from the outside caused the iron to crack, just like putting a hot glass in boiling water will cause it to crack. This caused cast iron cannon to have many imperceptible internal weaknesses, contributing to their bad reputation for reliability. Thomas Rodman, again in the mid-1850s, devised a method for cooling cast-iron cannon from the inside out. As the cannon cooled, outer layers would shrink around the inner layers, essentially pre-loading the entire structure with compression, giving the cannon many of the toughness advantages of wrought-iron construction.
With our understanding of steelmaking, the metallurgy that goes into cannon is much more advanced. Now we have complex heat treatment graphs for particular steel compositions depending on what combinations of properties we want- how hot to heat it to, how to cool it, how to temper the steel, all to produce a cannon that's light and durable.
Rifling throws an additional wrench into the works. Properly speaking, a "rifle" has rifling, and a "gun" does not. Rifling is generally made by cutting grooves into the inside of the barrel, so that some part of the projectile engages the rifling and causes the projectile to spin. This results in a much more accurate projectile, and consequently a longer effective range. However, especially with soft materials, having a hard projectile (most were cast iron!) come into contact with the barrel would cause an inordinate amount of wear; hence the Parrott rifles, aforementioned for their unreliability, were nevertheless used for their accuracy, having a cast-iron barrel.
Several strategies were devised around this, most commonly by surrounding some part of the projectile with a smooth, soft metal, like lead or copper. This soft metal is usually slightly wider than the actual barrel diameter, and is consequently forced into a seal around the base of the projectile when fired. This creates a good seal for the propellant gases to push against the projectile, and reduces wear on the rifling.
It's interesting that modern small arms design, having to work with its limitations, has seen a polygonal rifled barrel become popular- instead of a cylindrical inner barrel, the cross-section of the barrel is a polygon. This allows the force to be more evenly distributed around the barrel's surface area, instead of concentrated in the rifling grooves, and reduces wear on the barrel. This is even though most small arms ammunition is already designed to reduce wear on barrels, being surrounded with a copper jacket.
Now, the breech design contributes to whether your gun is going to burst or not. Early guns were all muzzle-loaders- you stuffed the propellant, more wadding, the projectile, and still more wadding into the front of the cannon. This was mainly because it was impossible (remember our materials and metallurgy?) to design a cannon that would open at the back and still fire reliably. You'd get leaks! Fire spurting from the non-business end! They were not well-received.
It wasn't until the development of the screw breech in the mid 1800s (yes, the 1800s was a great time for cannon development), and the development of industry capable of machining screw threads of such consistency and strength, that screw breeches became popular. Still into the late 1800s you get muzzle-loading cannon because they were inherently more reliable.
And as mentioned above, there was a great variety in the quality and consistency of workmanship, which we don't have to deal with in modern times. Industrial-scale ironmaking and steelmaking took a great long time to mature. So the lifespan of a cannon was generally up in the air- you'd fire it and hope for the best.
As a follow-up, would a naval cannon have a shorter lifespan than a similar field cannon, because of the saltwater?