Comparative study of foam stability in bulk and porous media