To my knowledge, we do not put comma before *which* but I have seen some sentences putting comma before *which*.

i.e. I don't like stories which have unhappy endings.

i.e. The heavy use of automobiles in urban areas, which could lead to a serious air pollution problem in cities.

Why the former one doesn't have comma before *which* but the latter one does?