thermal stress in single crystal thin films on a rigid substrate are used to study size effects. The relation between the residual stress and the dislocation structure in the films after cooling is analyzed using dislocation dynamics. A boundary layer characterized by a high stress gradient and a high dislocation density is found close to the impenetrable film-substrate interface. There is a material-dependent threshold film thickness above which the dislocation density together with the boundary layer thickness and stress state are independent of film thickness. In such films the stress outside the boundary layer is on average very low, so that the film-thickness-in dependent boundary layer is responsible for the size effect. A larger size effect is found for films thinner than the threshold thickness. The origin of this size effect stems from nucleation activity being hindered by the geometrical constraint of the small film thickness, so that by decreasing film thickness, the dislocation density decreases while the stress in the film increases. The size dependence is only described by a Hall-Petch type relation for films thicker than the threshold value.