Strange behaviour of pins

Greetings,

Recently I've experienced a very strange behaviour of my Mega 2560 boards. In my several sketches I use high amount of digital pinouts. I'm setting them mostly as OUTPUTS with either HIGH or LOW state. After some time of sketch running, I experience the spontaneous change of pin modes/voltage, for example pin that should be HIGH whole time, goes LOW (I know, that I can wire such line to +5/+3.3 V but that won't solve the problem). What might be the source of such problem and how can I overcome it?

Thanks in advance for Your help

What might be the source of such problem

Your code.

and how can I overcome it?

Fix your code.

If you want help in doing that then you have to post it. Be sure to read the how to use this forum first to see how to do it correctly.