Upper limit of entries in one bin and in whole histogram

TH2F bins are “Float / Single precision floating-point numbers” (4 Bytes = 32 bits)
TH2D bins are “Double precision floating-point numbers” (8 Bytes = 64 bits)
See also: Wikipedia - Floating point

You don’t say how your program crashes, but … If I were you I would start to search for “memory leaks” in the procedure that fills histograms.
Try to run your code using valgrind (and carefully study messages that appear in the beginning of the output):

valgrind --tool=memcheck --leak-check=full [--show-reachable=yes] [--num-callers=50] [--track-origins=yes] [--db-attach=yes] --suppressions=`root-config --etcdir`/valgrind-root.supp `root-config --bindir`/root.exe -l -q 'YourMacro.cxx[++][(Any, Parameters, You, Need)]'

or:

valgrind --tool=memcheck --leak-check=full [--show-reachable=yes] [--num-callers=50] [--track-origins=yes] [--db-attach=yes] --suppressions=`root-config --etcdir`/valgrind-root.supp YourExecutable [Any Options You Need]

(Note: the “–show-reachable=yes” option will give you too many warnings, I believe.)