Episodic ejections of blobs (episodic jets) are widely observed in black hole sources and usually associated with flares. In this paper, by performing and analyzing three-dimensional general relativity magnetohydrodynamical numerical simulations of accretion flows, we investigate their physical mechanisms. We find that magnetic reconnection occurs in the accretion flow, likely due to the turbulent motion and differential rotation of the accretion flow, resulting in flares and formation of flux ropes. Flux ropes formed inside of 10-15 gravitational radii are found to mainly stay within the accretion flow, while flux ropes formed beyond this radius are ejected outward by magnetic forces and form the episodic jets. These results confirm the basic scenario proposed in Yuan et al. Moreover, our simulations find that the predicted velocity of the ejected blobs is in good consistency with observations of Sgr A*, M81, and M87. All of the processes were found to occur quasiperiodically, with the period being the orbital time at the radius where the flux rope is formed. The predicted period of the flares and ejections is consistent with those found from the light curves or image of Sgr A*, M87, and PKS 1510-089. The possible applications to protostellar accretion systems are discussed.