Can having a heart bypass surgery affect the memory?

Yes. The effects of the cardiopulmonary bypass during the surgery together with somewhat lower blood flow to the brain and possible embolization of very small clots or calcified plaques from the major blood vessels (the latter two possible even in off bypass surgeries) can lead to memory changes. It is a very well documented side effect of cardiac surgery. In most cases the changes are minimal.
Yes. Brain damage can occur for a variety of reasons related to the surgery so that memory problems are not uncommon. Fortunately, most of the time they are temporary.