thanks for query,
You have not mentioned your age.If you are elderly then this may be due to artheritic changes occuring in the joint and lax surrounding muscles causing this problem.
In the young lack of physical activity,exercise,injury
to the joint in the past are common causes.
You go for Patellar exercise to strengthen the muscles and ligaments,go for exercise 10 mnt in the morning and 10 mnt in the evening.
You keep elasto crepe bandage or knee cap on the knee during the day time,remove during night.
ok and bye.